Bash
From Wsms
Note: This page should be titled bash (all lowercase). It is bash due to technical limitations of Mediawiki.
bash is the default shell in most Linux distributions.
Contents |
common usage
Open a terminal window and start typing
tips
The default shell for each user is set in /etc/passwd. See 20061018.
common aliases
Many people add these aliases to their ~/.bashrc:
# User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' export VISUAL=emacs export PATH=$PATH:~/bin
customize your prompt
The prompt is customized through the PS1, PS2, PS3 ... shell variables.
The typical setting for $PS1 is:
${debian_chroot:+($debian_chroot)}\u@\h:\w\$
Which translates to something like:
ggeller@grant:~/Desktop/johnson-20050927.bu$
Sometimes the prompt is too long. So, reset it for the session by changing the value of PS1 to something like a $ or the basename of the current working directory.
ggeller@grant:~/Desktop/johnson-20050927.bu$ export PS1='$ ' $ export PS1='\W $ ' johnson-20050927.bu $
redirecting output
This command sends the output to a file and the screen at the same time:
ggeller@harrison:~$ find /root 2>&1 | tee find.out
Notice that the error-output is also visible in both the screen and the saved file.
Sometime redirection can be confusing. Here is an example from man bash:
Note that the order of redirections is significant. For example, the command
ls > dirlist 2>&1 # correct
directs both standard output and standard error to the file dirlist, while the command
ls 2>&1 > dirlist # incorrect
directs only the standard output to file dirlist, because the standard error was duplicated as standard output before the standard output was redirected to dirlist.
see also
20061009
20061010
20061011
20061018
20061019
20061020
20070323a
Factorial_bash_script
http://www.oreilly.com/catalog/bash3/ "Learning the Bash Shell, 3rd Edition"
http://www.kernel-panic.org/Members/pacneil/beginner/node39.html
http://tldp.org/LDP/abs/html/ Advanced bashed scripting guide
Learning the bash Shell, 3rd Edition By Cameron Newham
