Welcome to the Slackware Documentation Project

Differences

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

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
slackbook:bash [2012/09/02 21:37 (UTC)]
mfillpot created - copied content and set formatting
slackbook:bash [2012/09/12 19:55 (UTC)]
mfillpot updated code block to syntax highlighting
Line 4: Line 4:
 ===== What Is A Shell? ===== ===== What Is A Shell? =====
  
-Yeah, what exactly is a shell? Well, a shell is basically a command-line user environment. In essence, it is an application that runs when the user logs in and allows him to run additional applications. In some ways it is very similar to a graphical user interface, in that it provides a framework for executing commands and launching programs. There are many shells included with a full install of Slackware, but in this book we're only going to discuss bash(1), the Bourne Again Shell. Advanced users might want to consider using the powerful zsh(1), and users familiar with older UNIX systems might appreciate ksh. The truly masochistic might choose the csh, but new users should stick to bash. +Yeah, what exactly is a shell? ​ Well, a shell is basically a 
 +command-line user environment. ​ In essence, it is an application that 
 +runs when the user logs in and allows him to run additional 
 +applications. ​ In some ways it is very similar to a graphical user 
 +interface, in that it provides a framework for executing commands and 
 +launching programs. ​ There are many shells included with a full install 
 +of Slackware, but in this book we're only going to discuss 
 +**//bash//**(1), the Bourne Again Shell. Advanced 
 +users might want to consider using the powerful 
 +**//zsh//**(1), and users familiar with older UNIX 
 +systems might appreciate ​**//ksh//**. The truly 
 +masochistic might choose the **//csh//**, but new 
 +users should stick to **//bash//**.
 ===== Environment Variables ===== ===== Environment Variables =====
  
-All shells make certain tasks easier for the user by keeping track of things in environment variables. An environment variable is simply a shorter name for some bit of information that the user wishes to store and make use of later. For example, the environment variable PS1 tells bash how to format its prompt. Other variables may tell applications how to run. For example, the LESSOPEN variable tells less to run that handy lesspipe.sh preprocessor we talked about, and LS_OPTIONS tuns on color for ls.+All shells make certain tasks easier for the user by keeping track of 
 +things in environment variables. ​ An environment variable is simply a 
 +shorter name for some bit of information that the user wishes to store 
 +and make use of later. ​ For example, the environment variable PS1 tells 
 +**//bash//** how to format its prompt. ​ Other 
 +variables may tell applications how to run.  For example, the LESSOPEN 
 +variable tells **//less//** to run that handy 
 +''​lesspipe.sh'' ​preprocessor we talked about, and 
 +LS_OPTIONS tuns on color for **//ls//**.
  
-Setting your own envirtonment variables is easy. bash includes two built-in functions for handling this: set and export. Additionally,​ an environment variable can be removed by using unset. (Don't panic if you accidently unset an environment variable and don't know what it would do. You can reset all the default variables by logging out of your terminal and logging back in.) You can reference a variable by placing a dollar sign ($) in front of it. 
  
-<​code>​+Setting your own envirtonment variables is easy. 
 +**//​bash//​** includes two built-in functions for 
 +handling this: **//set//** and 
 +**//​export//​**. ​ Additionally,​ an environment 
 +variable can be removed by using **//​unset//​**. 
 +(Don't panic if you accidently unset an environment variable and don'​t 
 +know what it would do.  You can reset all the default variables by 
 +logging out of your terminal and logging back in.)  You can reference a 
 +variable by placing a dollar sign ($) in front of it. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ set FOO=bar darkstar:~$ set FOO=bar
 darkstar:~$ echo $FOO darkstar:~$ echo $FOO
Line 18: Line 47:
 </​code>​ </​code>​
  
-The primary difference between set and export is that export will (naturally) export the variable to any sub-shells. (A sub-shell is simply another shell running inside a parent shell.) You can easily see this behavior when working with the PS1 variable that controls the bash prompt. 
  
-<​code>​+The primary difference between **//set//** and 
 +**//​export//​** is that 
 +**//​export//​** will (naturally) export the variable 
 +to any sub-shells. ​ (A sub-shell is simply another shell running inside 
 +a parent shell.) ​ You can easily see this behavior when working with 
 +the PS1 variable that controls the **//​bash//​** 
 +prompt. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ set PS1='​FOO ' darkstar:~$ set PS1='​FOO '
 darkstar:~$ export PS1='​FOO ' darkstar:~$ export PS1='​FOO '
Line 26: Line 63:
 </​code>​ </​code>​
  
-There are many important environment variables that bash and other shells use, but one of the most important ones you will run across is PATH. PATH is simply a list of directories to search through for applications. For example, top(1) is located at /​usr/​bin/​top. You could run it simply by specifying the complete path to it, but if /usr/bin is in your PATH variable, bash will check there if you don't specify a complete path one your own. You will most likely first notice this when you attempt to run a program that is not in your PATH as a normal user, for instance, ifconfig(8). 
  
-<​code>​+There are many important environment variables that 
 +**//​bash//​** and other shells use, but one of the 
 +most important ones you will run across is PATH.  PATH is simply a list 
 +of directories to search through for applications. ​ For example, 
 +**//​top//​**(1) is located at 
 +**///​usr/​bin/​top//​**. ​ You could run it simply by 
 +specifying the complete path to it, but if 
 +''/​usr/​bin''​ is in your PATH variable, 
 +**//​bash//​** will check there if you don't specify a 
 +complete path one your own.  You will most likely first notice this 
 +when you attempt to run a program that is not in your PATH as a normal 
 +user, for instance, **//​ifconfig//​**(8). 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ ifconfig darkstar:~$ ifconfig
 bash: ifconfig: command not found bash: ifconfig: command not found
Line 35: Line 85:
 </​code>​ </​code>​
  
-Above, you see a typical PATH for a mortal user. You can change it on your own the same as any other environment variable. If you login as root however, you'll see that root has a different PATH. 
  
-<​code>​+Above, you see a typical PATH for a mortal user.  You can change it on 
 +your own the same as any other environment variable. ​ If you login as 
 +root however, you'll see that root has a different PATH. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ su - darkstar:~$ su -
 Password: ​ Password: ​
Line 43: Line 97:
 /​usr/​local/​sbin:/​usr/​sbin:/​sbin:/​usr/​local/​bin:/​usr/​bin:/​bin:/​usr/​X11R6/​bin:/​usr/​games:/​opt/​www/​htdig/​bin /​usr/​local/​sbin:/​usr/​sbin:/​sbin:/​usr/​local/​bin:/​usr/​bin:/​bin:/​usr/​X11R6/​bin:/​usr/​games:/​opt/​www/​htdig/​bin
 </​code>​ </​code>​
- 
 ===== Wildcards ===== ===== Wildcards =====
  
-Wildcards are special characters that tell the shell to match certain criteria. If you have experience with DOS, you'll recognize * as a wildcard that matches anything. bash makes use of this wildcard and several others to enable you to easily define exactly what you want to do.+Wildcards are special characters that tell the shell to match certain 
 +criteria. ​ If you have experience with DOS, you'll recognize * as a 
 +wildcard that matches anything. ​ **//bash//** makes 
 +use of this wildcard and several others to enable you to easily define 
 +exactly what you want to do
 + 
 + 
 +This first and most common of these is, of course, *.  The asterisk 
 +matches any character or combination of characters, including none. 
 +Thus b* would match any files named b, ba, bab, 
 +babc, bcdb, and so forth. ​ Slightly less common is the ?.  This 
 +wildcard matches one instance of any character, so 
 +b? would match ba and bb, but not b or bab.
  
-This first and most common of these is, of course, *. The asterisk matches any character or combination of characters, including none. Thus b* would match any files named b, ba, bab, babc, bcdb, and so forth. Slightly less common is the ?. This wildcard matches one instance of any character, so b? would match ba and bb, but not b or bab. 
  
-<​code>​+<​code ​bash>
 darkstar:~$ touch b ba bab darkstar:~$ touch b ba bab
 darkstar:~$ ls * darkstar:~$ ls *
Line 58: Line 122:
 </​code>​ </​code>​
  
-No, the fun doesn'​t stop there! In addition to these two we also have the bracket pair "[ ]" which allows us to fine tune exactly what we want to match. Whenever bash see the bracket pair, it substitutes the contents of the bracket. Any combination of letters or numbers may be specified in the bracket as long as they are comma seperated. Additionally,​ ranges of numbers and letters may be specified as well. This is probably best shown by example. 
  
-<​code>​+No, the fun doesn'​t stop there! ​ In addition to these two we also have 
 +the bracket pair //"[ ]"// which allows us to fine tune exactly what we 
 +want to match. ​ Whenever **//​bash//​** see the 
 +bracket pair, it substitutes the contents of the bracket. ​ Any 
 +combination of letters or numbers may be specified in the bracket as 
 +long as they are comma seperated. ​ Additionally,​ ranges of numbers and 
 +letters may be specified as well.  This is probably best shown by 
 +example. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ ls a[1-4,9] darkstar:~$ ls a[1-4,9]
 a1 a2 a3 a4 a9 a1 a2 a3 a4 a9
 </​code>​ </​code>​
  
-Since Linux is case-sensitive,​ capital and lower-case letters are treated differently. All capital letters come before all lower-case letters in "​alphabetical"​ order, so when using ranges of capital and lower-case letters, make sure to get them right. 
  
-<​code>​+Since Linux is case-sensitive,​ capital and lower-case letters are 
 +treated differently. ​ All capital letters come before all lower-case 
 +letters in //"​alphabetical"//​ order, so when using ranges of capital and 
 +lower-case letters, make sure to get them right. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ ls 1[W-b] darkstar:~$ ls 1[W-b]
 1W 1X 1Y 1Z 1a 1b 1W 1X 1Y 1Z 1a 1b
Line 74: Line 152:
 </​code>​ </​code>​
  
-In the second example, 1[b-W] isn't a valid range, so the shell treats it as a filename, and since that file doesn'​t exist, ls tells you so. 
  
 +In the second example, 1[b-W] isn't a valid range, so the shell treats
 +it as a filename, and since that file doesn'​t exist,
 +**//ls//** tells you so.
 ===== Tab Completion ===== ===== Tab Completion =====
  
-Still think there'​s entirely too much work involved with using wildcards? You're right. There'​s an even easier way when you're dealing with long filenames: tab completion. Tab completion enables you to type just enough of the filename to uniquely identify it, then by hitting the TAB key, bash will fill in 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. Hitting TAB a second time will make it display a list of all possible matches for you. +Still think there'​s entirely too much work involved with using 
 +wildcards? ​ You're right. ​ There'​s an even easier way when you're 
 +dealing with long filenames: tab completion. ​ Tab completion enables 
 +you to type just enough of the filename to uniquely identify it, then 
 +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 
 +identify a filename, the shell will fill in as much as it can for you. 
 +Hitting TAB a second time will make it display a list of all possible 
 +matches for you.
 ===== Input and Output Redirection ===== ===== Input and Output Redirection =====
  
-One of the defining features of Linux and other UNIX-like operating systems is the number of small, relatively simple applications and the ability to stack them together to create complex systems. This is achieved by redirecting the output of one program to another, or by drawing input from a file or second program.+One of the defining features of Linux and other UNIX-like operating 
 +systems is the number of small, relatively simple applications and the 
 +ability to stack them together to create complex systems. ​ This is 
 +achieved by redirecting the output of one program to another, or by 
 +drawing input from a file or second program.
  
-To get started, we're going to show you how to redirect the output of a program to a file. This is easily done with the '>'​ character. When bash sees the '>'​ character, it redirects all of the standard output (also known as stdout) to whatever file name follows. + 
-<​code>​+To get started, we're going to show you how to redirect the output of a 
 +program to a file.  This is easily done with the '>'​ character. ​ When 
 +**//bash//** sees the '>'​ character, it redirects 
 +all of the standard output (also known as stdout) to whatever file name 
 +follows. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ echo foo darkstar:~$ echo foo
 foo foo
Line 93: Line 191:
 </​code>​ </​code>​
  
-In this example, we show you what echo would do if its stdout was not redirected to a file, then we re-direct it to the /tmp/bar file. If /tmp/bar does not exist, it is created and the output from echo is placed within it. If /tmp/bar did exist, then its contents are over-written. This might not be the best idea if you want to keep those contents in place. Thankfully, bash supports '>>'​ which will append the output to the file. 
  
-<​code>​+In this example, we show you what **//​echo//​** would 
 +do if its stdout was not redirected to a file, then we re-direct it to 
 +the ''/​tmp/​bar''​ file.  If ''/​tmp/​bar''​ 
 +does not exist, it is created and the output from 
 +**//​echo//​** is placed within it.  If 
 +''/​tmp/​bar''​ did exist, then its contents are 
 +over-written. ​ This might not be the best idea if you want to keep 
 +those contents in place. ​ Thankfully, **//​bash//​** 
 +supports '>>'​ which will append the output to the file. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ echo foo darkstar:~$ echo foo
 foo foo
Line 107: Line 215:
 </​code>​ </​code>​
  
-You can also re-direct the standard error (or stderr) to a file. This is slightly different in that you must use '​2>'​ instead of just '>'​. (Since bash can re-direct input, stdout, and stderr, each must be uniquely identifiable. 0 is input, 1 is stdout, and 2 is stderr. Unless one of these is specified, bash will make its best guess as to what you actually meant, and assumed anytime you use '>'​ you only want to redirect stdout. 1> would have worked just as well.) 
  
-<​code>​+You can also re-direct the standard error (or stderr) to a file.  This 
 +is slightly different in that you must use '​2>'​ instead of just '>'​. 
 +(Since **//​bash//​** can re-direct input, stdout, and 
 +stderr, each must be uniquely identifiable. ​ 0 is input, 1 is stdout, 
 +and 2 is stderr. ​ Unless one of these is specified,​ 
 +**//​bash//​** will make its best guess as to what you 
 +actually meant, and assumed anytime you use '>'​ you only want to 
 +redirect stdout. ​ 1> would have worked just as well.) 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ rm bar darkstar:~$ rm bar
 rm: cannot remove `bar': No such file or directory rm: cannot remove `bar': No such file or directory
Line 117: Line 234:
 </​code>​ </​code>​
  
-You may also redirect the standard input (known as stdin) with the '<'​ character, though it's not used very often. 
  
-<​code>​+You may also redirect the standard input (known as stdin) with the 
 +'<'​ 
 +character, though it's not used very often. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ fromdos < dosfile ​ darkstar:~$ fromdos < dosfile ​
 </​code>​ </​code>​
  
-Finally, you can actually redirect the output of one program as input to another. This is perhaps the most useful feature of bash and other shells, and is accomplished using the '​|'​ character. (This character is referred to as '​pipe'​. If you here some one talk of piping one program to another, this is exactly what they mean.) 
  
-<​code>​+Finally, you can actually redirect the output of one program as input 
 +to another. ​ This is perhaps the most useful feature of 
 +**//​bash//​** and other shells, and is accomplished 
 +using the '​|'​ character. ​ (This character is referred to as '​pipe'​. 
 +If you here some one talk of piping one program to another, this is 
 +exactly what they mean.) 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ ps auxw | grep getty darkstar:~$ ps auxw | grep getty
 root      2632  0.0  0.0   ​1656 ​  532 tty2     ​Ss+ ​ Feb21   0:00 /​sbin/​agetty 38400 tty2 linux root      2632  0.0  0.0   ​1656 ​  532 tty2     ​Ss+ ​ Feb21   0:00 /​sbin/​agetty 38400 tty2 linux
Line 133: Line 261:
 root      3202  0.0  0.0   ​1660 ​  536 tty6     ​Ss+ ​ Feb15   0:00 /​sbin/​agetty 38400 tty6 linux root      3202  0.0  0.0   ​1660 ​  536 tty6     ​Ss+ ​ Feb15   0:00 /​sbin/​agetty 38400 tty6 linux
 </​code>​ </​code>​
- 
 ===== 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 ​bash>
 darkstar:~$ jobs darkstar:~$ jobs
 [1]-  Stopped ​                vi TODO [1]-  Stopped ​                vi TODO
Line 144: 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. 
  
-<​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. 
 + 
 + 
 +<​code ​bash>
 darkstar:~$ fg # "vi TODO" darkstar:~$ fg # "vi TODO"
 darkstar:~$ fg 1 # "vi chapter_05.xml"​ darkstar:~$ fg 1 # "vi chapter_05.xml"​
 </​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. 
  
-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 terminalsbut 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 interfacecheck 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 environmentsExecuting ​any of these will give you a graphical terminal and automatically run your default shell.+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 timesperhaps as different users, and run 
 +applications ​in those users' shells silmutaneouslyThis 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.
 ===== 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 bash> 
 +alan@darkstar:​~$ </​code>​ 
  
-<​code>​ 
-alan@darkstar:​~$ ​ 
-</​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>​ 
-bash-3.1$ ​ 
-</​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.)+<code bash> 
 +bash-3.1$ </​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.) 
 + 
 + 
 +<code bash>
  
-<​code>​ 
 # ~/.bashrc # ~/.bashrc
 . /​etc/​profile . /​etc/​profile
Line 182: 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 preferancesPersonallyI prefer short and simple prompts that take up minimum of spacebut I've seen and used mutli-line prompts many timesOne personal friend of mine even included ASCII-art in his bash promptTo change your prompt ​you need only to change your PS1 variableBy default, Slackware attempts to configure your PS1 variable thusly:+When using the aboveall your login and interactive shells will have 
 +the same environment settings ​and behave identicallyNowanytime we 
 +wish to customize ​shell settingwe only have to edit 
 +''~/.bash_profile''​ for user-specific changes and 
 +''/​etc/​profile''​ for global settingsLet's start by 
 +configuring the prompt.
  
-<​code>​+ 
 +**//​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 ​bash>
 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 \, 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.+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'​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 <​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.
  
-<​code>​+ 
 +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 ​bash>
 Wed Jan 14 12:08 AM Wed Jan 14 12:08 AM
 alan@raven:​~$ echo $PS1 alan@raven:​~$ echo $PS1
Line 204: 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]] -->
  
 <!-- Please do not modify anything below, except adding new tags.--> <!-- Please do not modify anything below, except adding new tags.-->
 <!-- You must also remove the tag-word "​template"​ below. Otherwise your page will not show up in the Table of Contents --> <!-- You must also remove the tag-word "​template"​ below. Otherwise your page will not show up in the Table of Contents -->
-{{tag>​slackbook bash}}+{{tag>​slackbook bash task_management terminals}}

In Other Languages
QR Code
QR Code slackbook:bash (generated for current page)