|
The bash Shell Why bash?
Environment Variables [user@host user]$ env HISTSIZE=1000 HOSTNAME=host LOGNAME=user HISTFILESIZE=1000 MAIL=/var/spool/mail/user TERM=xterm HOSTTYPE=i386 PATH=/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin HOME=/home/user INPUTRC=/etc/inputrc SHELL=/bin/bash PS1=[\u@\h \W]\$ USER=user LC_ALL=en_US LANG=en_US OSTYPE=Linux LINGUAS=en_US SHLVL=1 _=/usr/bin/env [user@host user]$ export MYVAR='hello world' [user@host user]$ echo $MYVAR hello world [user@host user]$ unset MYVAR [user@host user]$ echo $MYVAR [user@host user]$ MYVAR='hello world' printenv MYVAR hello world [user@host user]$ export CDPATH=:/usr/web [user@host user]$ ls [user@host user]$ cd htdocs /usr/web/htdocs [user@host htdocs]$Aliases [user@host user]$ alias ls='ls --color' [user@host user]$ alias l='ls -alF' [user@host user]$ alias cc='/usr/bin/gcc -Wall -ansi -pedantic' [user@host user]$ alias alias cc='/usr/bin/gcc -Wall -ansi -pedantic' alias l='ls -alF' alias ls='ls --color' [user@host user]$ unalias cc [user@host user]$ alias cc alias: `cc' not foundOptions [user@host user]$ set -o [user@host user]$ help setFunctions [user@host user]$ declare -f mc mc () { mkdir -p ~/.mc/tmp 2>/dev/null; chmod 700 ~/.mc/tmp; MC=~/.mc/tmp/mc$$-"$RANDOM"; /usr/bin/mc -P "$@" >"$MC"; cd "`cat $MC`"; rm "$MC"; unset MC } [user@host user]$ unset -f mc [user@host user]$ declare -f mc [user@host user]$ function demofunc > { > echo demofunc got ${#} positional parameters > while [ ${#} -gt 0 ] > do > echo "${1}" > shift > done > } [user@host user]$ declare -f demofunc demofunc () { echo demofunc got ${#} positional parameters; while [ ${#} -gt 0 ]; do echo "${1}"; shift; done } [user@host user]$ demofunc a b c demofunc got 3 positional parameters a b cMisc - Prompting
My favorite: [user@host user]$ export PS1="\! \t\w> "Misc - Redirection Redirect Standard Input [user@host user]$ sort < /etc/passwd Redirect Standard Output [user@host user]$ ls > dirlist Append to a File [user@host user]$ ls /etc >> dirlist Redirect Standard Error [user@host user]$ ls /no_such_directory 2> /dev/null Redirect Standard Output and Standard Error [user@host user]$ ls / /no_such_directory > dirlist 2> /dev/null Redirect Standard Output and Standard Error to the same place [user@host user]$ ls / /no_such_directory > dirlist 2>&1 - or - [user@host user]$ ls / /no_such_directory &> dirlist Pipeline [user@host user]$ du -sk * | sort -rn | head -5 Redirect Standard Input and Pipeline [user@host user]$ awk -F: '{print $7}' < /etc/passwd | sort | uniq Last updated |