[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
slackbook:bash [2012/09/08 18:02 (UTC)] – [Input and Output Redirection] updated section to match original with formatting mfillpotslackbook:bash [2012/10/14 15:52 (UTC)] (current) – removed all bash flags mfillpot
Line 162: Line 162:
 dealing with long filenames: tab completion.  Tab completion enables dealing with long filenames: tab completion.  Tab completion enables
 you to type just enough of the filename to uniquely identify it, then you to type just enough of the filename to uniquely identify it, then
-by hitting the <key>TAB</key> key, **//bash//** will fill in+by hitting the <key>'TAB'</key> key, **//bash//** will fill in
 the rest for you.  Even if you haven't typed in enough text to uniquely the rest for you.  Even if you haven't typed in enough text to uniquely
 identify a filename, the shell will fill in as much as it can for you. identify a filename, the shell will fill in as much as it can for you.
Line 263: Line 263:
 ===== Task Management ===== ===== Task Management =====
  
-bash has yet another cool feature to offer, the ability to suspend and resume tasks. This allows you to temporarily halt a running process, perform some other task, then resume it or optionally make it run in the background. Upon pressing CTRL-Z, bash will suspend the running process and return you to a prompt. You can return to that process later. Additionally, you can suspend multiple processes in this way indefinitely. The jobs built-in command will display a list of suspended tasks.+**//bash//** has yet another cool feature to offer, 
 +the ability to suspend and resume tasks.  This allows you to 
 +temporarily halt a running process, perform some other task, then 
 +resume it or optionally make it run in the background. Upon pressing 
 +<key>'CTRL'</key>+<key>'z'</key>**//bash//** will suspend 
 +the running process and return you to a prompt. You can return to that 
 +process later.  Additionally, you can suspend multiple processes in 
 +this way indefinitely.  The **//jobs//** built-in 
 +command will display a list of suspended tasks. 
  
 <code> <code>
Line 271: Line 280:
 </code> </code>
  
-In order to return to a suspended task, run the fg built-in to bring the the most recently suspended task back into the foreground. If you have mutiple suspended tasks, you can specify a number as well to bring one of them to the foreground.+ 
 +In order to return to a suspended task, run the 
 +**//fg//** built-in to bring the the most recently 
 +suspended task back into the foreground. If you have mutiple suspended  
 +tasks, you can specify a number as well to bring one of them to the 
 +foreground. 
  
 <code> <code>
Line 278: Line 293:
 </code> </code>
  
-You can also background a task with (surprize) bg. This will allow the process to continue running without maintaining control of your shell. You can bring it back to the foreground with fg in the same way as suspended tasks.+ 
 +You can also background a task with (surprize) 
 +**//bg//**. This will allow the process to continue 
 +running without maintaining control of your shell. You can bring it 
 +back to the foreground with **//fg//** in the same 
 +way as suspended tasks.
  
 ===== Terminals ===== ===== Terminals =====
  
-Slackware Linux and other UNIX-like operating systems allow users to interact with them in many ways, but the most common, and arguably the most useful, is the terminal. In the old days, terminals were keyboards and monitors (sometimes even mice) wired into a mainframe or server via serial connections. Today however, most terminals are virtual; that is, they exist only in software. Virtual terminals allow users to connect to the computer without requiring expensive and often incompatible hardware. Rather, a user needs only to run the software and they are presented with a (usually) highly customizable virtual terminal.+Slackware Linux and other UNIX-like operating systems allow users to 
 +interact with them in many ways, but the most common, and arguably the 
 +most useful, is the terminal. In the old days, terminals were keyboards 
 +and monitors (sometimes even mice) wired into a mainframe or server via 
 +serial connections. Today however, most terminals are virtual; that is, 
 +they exist only in software.  Virtual terminals allow users to connect 
 +to the computer without requiring expensive and often incompatible 
 +hardware. Rather, a user needs only to run the software and they are 
 +presented with a (usually) highly customizable virtual terminal. 
  
-The most common virtual terminals (in that every Slackware Linux machine is going to have at least one) are the gettys. agetty(8) runs six instances by default on Slackware, and allows local users (those who can physically sit down in front of the computer and type at the keyboard) to login and run applications. Each of these gettys is available on different tty devices that are accessible seperately by pressing the **ALT** key and one of the function keys from **F1** through **F6**. Using these gettys allows you to login multiple times, perhaps as different users, and run applications in those users' shells silmutaneously. This is most commonly done with servers which do not have X installed, but can be done on any machine.+The most common virtual terminals (in that every Slackware Linux machine 
 +is going to have at least one) are the gettys. 
 +**//agetty//**(8) runs six instances by default on 
 +Slackware, and allows local users (those who can physically sit down in 
 +front of the computer and type at the keyboard) to login and run 
 +applications. Each of these gettys is available on different tty 
 +devices that are accessible seperately by pressing the 
 +<key>'ALT'</key> key and one of the function keys from 
 +<key>'F1'</key> through <key>'F6'</key>. Using these gettys 
 +allows you to login multiple times, perhaps as different users, and run 
 +applications in those users' shells silmutaneously. This is most 
 +commonly done with servers which do not have 
 +**//X//** installed, but can be done on any machine.
  
-On desktops, laptops, and other workstations where the user prefers a graphical interface provided by X, most terminals are graphical. Slackware includes many different graphical terminals, but the most commonly used are KDE's konsole and XFCE's Terminal(1) as well as the old standby, xterm(1). If you are using a graphical interface, check your tool bars or menus. Each desktop environment or window manager has a virtual terminal (often called a terminal emulater), and they are all labelled differently. Typically though, you will find them under a "System" sub-menu in desktop environments. Executing any of these will give you a graphical terminal and automatically run your default shell. 
  
 +On desktops, laptops, and other workstations where the user prefers a
 +graphical interface provided by **//X//**, most
 +terminals are graphical.  Slackware includes many different graphical
 +terminals, but the most commonly used are KDE's
 +**//konsole//** and XFCE's
 +**//Terminal//**(1) as well as the old standby,
 +xterm(1). If you are using a graphical interface, check your tool bars
 +or menus. Each desktop environment or window manager has a virtual
 +terminal (often called a terminal emulater), and they are all labelled
 +differently. Typically though, you will find them under a //"System"//
 +sub-menu in desktop environments. Executing any of these will give you
 +a graphical terminal and automatically run your default shell.
 ===== Customization ===== ===== Customization =====
  
-By now you should be pretty familiar with bash and you may have even noticed some odd behavior. For example, when you login at the console, you're presented with a prompt that looks a bit like this.+By now you should be pretty familiar with 
 +**//bash//** and you may have even noticed some odd 
 +behavior. For example, when you login at the console, you're presented 
 +with a prompt that looks a bit like this. 
  
 <code> <code>
-alan@darkstar:~$  +alan@darkstar:~$ </code> 
-</code>+ 
 However, sometimes you'll see a much less helpful prompt like this one. However, sometimes you'll see a much less helpful prompt like this one.
 +
  
 <code> <code>
-bash-3.1$  +bash-3.1$ </code> 
-</code>+ 
 + 
 +The cause here is a special environment variable that controls the 
 +**//bash//** prompt. Some shells are considered 
 +//"login"// shells and others are //"interactive"// shells, and both types read 
 +different configuration files when started. Login shells read 
 +''/etc/profile'' and 
 +''~/.bash_profile'' when executed. Interactive shells 
 +read ''~/.bashrc'' instead. This has some advantages 
 +for power users, but is a common annoyance for many new users who want 
 +the same environment anytime they execute 
 +**//bash//** and don't care about the difference 
 +between login and interactive shells. If this applies to you, simply 
 +edit your own ~/.bashrc file and include the following lines. 
 +(For more information on 
 +the different configuration files used, read the INVOCATION section of 
 +the **//bash//** man page.)
  
-The cause here is a special environment variable that controls the bash prompt. Some shells are considered "login" shells and others are "interactive" shells, and both types read different configuration files when started. Login shells read /etc/profile and ~/.bash_profile when executed. Interactive shells read ~/.bashrc instead. This has some advantages for power users, but is a common annoyance for many new users who want the same environment anytime they execute bash and don't care about the difference between login and interactive shells. If this applies to you, simply edit your own ~/.bashrc file and include the following lines. (For more information on the different configuration files used, read the INVOCATION section of the bash man page.) 
  
 <code> <code>
 +
 # ~/.bashrc # ~/.bashrc
 . /etc/profile . /etc/profile
Line 309: Line 383:
 </code> </code>
  
-When using the above, all your login and interactive shells will have the same environment settings and behave identically. Now, anytime we wish to customize a shell setting, we only have to edit ~/.bash_profile for user-specific changes and /etc/profile for global settings. Let's start by configuring the prompt. 
  
-bash prompts come in all shapes, colors, and sizes, and every user has their own preferances. Personally, I prefer short and simple prompts that take up a minimum of space, but I've seen and used mutli-line prompts many times. One personal friend of mine even included ASCII-art in his bash prompt. To change your prompt you need only to change your PS1 variable. By default, Slackware attempts to configure your PS1 variable thusly:+When using the above, all your login and interactive shells will have 
 +the same environment settings and behave identically. Now, anytime we 
 +wish to customize a shell setting, we only have to edit 
 +''~/.bash_profile'' for user-specific changes and 
 +''/etc/profile'' for global settings. Let's start by 
 +configuring the prompt. 
 + 
 + 
 +**//bash//** prompts come in all shapes, colors, and 
 +sizes, and every user has their own preferances. Personally, I prefer 
 +short and simple prompts that take up a minimum of space, but I've seen 
 +and used mutli-line prompts many times. One personal friend of mine 
 +even included ASCII-art in his bash prompt. To change your prompt you 
 +need only to change your PS1 variable. By default, Slackware attempts 
 +to configure your PS1 variable thusly: 
  
 <code> <code>
 darkstar:~$ echo $PS1 darkstar:~$ echo $PS1
-\u@\h:\w\$  +\u@\h:\w\$ </code> 
-</code>+ 
 + 
 +Yes, this tiny piece of funny-looking figures controls your 
 +**//bash//** prompt. Basicaly, every character in 
 +the PS1 variable is included in the prompt, unless it is a escaped by a 
 +<key>'\'</key>, which tells **//bash//** to 
 +interpret it. There are many different escape sequences and we can'
 +discuss them all, but I'll explain these.  The first //"\u"// translates to 
 +the username of the current user.  //"\h"// is the hostname of the machine 
 +the terminal is attached to. //"\w"// is the current working directory, and 
 +//"\$"// displays either a <key>'#'</key> or a <key>'$'</key> sign, 
 +depending on whether or not the current user is root.  A complete 
 +listing of all prompt escape sequences is listed in the 
 +**//bash//** man page under the PROMPTING section. 
  
-Yes, this tiny piece of funny-looking figures controls your bash prompt. Basicaly, every character in the PS1 variable is included in the prompt, unless it is a escaped by a \, which tells bash to interpret it. There are many different escape sequences and we can't discuss them all, but I'll explain these. The first "\u" translates to the username of the current user. "\h" is the hostname of the machine the terminal is attached to. "\w" is the current working directory, and "\$" displays either a # or a $ sign, depending on whether or not the current user is root. A complete listing of all prompt escape sequences is listed in the bash man page under the PROMPTING section.+Since we've gone through all this trouble to discuss the default 
 +prompt, I thought I'd take some time to show you a couple example 
 +prompts and the PS1 variable values needed to use them.
  
-Since we've gone through all this trouble to discuss the default prompt, I thought I'd take some time to show you a couple example prompts and the PS1 variable values needed to use them. 
  
 <code> <code>
Line 331: Line 434:
 </code> </code>
  
-For even more information on configuring your bash prompt, including information on setting up colored prompts, refer to /usr/doc/Linux-HOWTOs/Bash-Prompt-HOWTO. After reading that for a short while, you'll get an idea of just how powerful your bash prompts can be. I once even had a prompt that gave me up to date weather information such as temperature and barometric pressure! 
  
 +For even more information on configuring your bash prompt, including
 +information on setting up colored prompts, refer to
 +''/usr/doc/Linux-HOWTOs/Bash-Prompt-HOWTO''. After
 +reading that for a short while, you'll get an idea of just how powerful
 +your **//bash//** prompts can be. I once even had a
 +prompt that gave me up to date weather information such as temperature
 +and barometric pressure!
 +
 +====== Chapter Navigation ======
 +
 +**Previous Chapter: [[slackbook:shell|Basic Shell Commands]]**
 +
 +**Next Chapter: [[slackbook:process_control|Process Control]]**
 ====== Sources ====== ====== Sources ======
 <!-- If you copy information from another source, then specify that source --> <!-- If you copy information from another source, then specify that source -->
- * Original source: [[http://www.slackbook.org/beta/#ch_bash]] +  * Original source: [[http://www.slackbook.org/beta]] \\
 <!-- Authors are allowed to give credit to themselves! --> <!-- Authors are allowed to give credit to themselves! -->
-<!-- * Originally written by [[wiki:user:xxx | User X]] -->+  * Originally written by Alan Hicks, Chris Lumens, David Cantrell, Logan Johnson
 <!-- * Contrbutions by [[wiki:user:yyy | User Y]] --> <!-- * Contrbutions by [[wiki:user:yyy | User Y]] -->
  
 slackbook:bash ()