*** bash - 2005-09-20 *** EXPANSIONS ========== Brace expansion -------------- {b,c}d is expanded to abd acd (note: brace: { }, square bracket: [ ], parenthesis: ( ) ) examples: root@dolphin:~/test# echo E-mail: {Smith,Tailor}@ieee.org E-mail: Smith@ieee.org Tailor@ieee.org -- root@dolphin:~/test# echo lencse@{{mail,rs1}.,""}{szif,sze}.hu lencse@mail.szif.hu lencse@mail.sze.hu lencse@rs1.szif.hu lencse@rs1.sze.hu lencse@szif.hu lencse@sze.hu Tilde expansion --------------- ~lencse/public_html examples: root@dolphin:~/test# cd ~lencse root@dolphin:/home/lencse# -- root@dolphin:~/test# lynx http://dolphin.szif.hu/~lencse Parameter Expansion ------------------- $parameter or ${parameter} example: root@dolphin:~# alma=apple root@dolphin:~# echo $alma apple Command Substitution -------------------- $(command) or `command` examples: root@dolphin:~/test# ls 11 111 121 131 root@dolphin:~/test# rm `ls` root@dolphin:~/test# ls root@dolphin:~/test# -- something more useful is: rm `find -name core` -- root@dolphin:~# echo "1. sor" > probafile root@dolphin:~# echo "2. sor" >> probafile root@dolphin:~# echo `cat probafile` 1. sor 2. sor -- explanation: see word splitting root@dolphin:~# echo `< probafile` 1. sor 2. sor root@dolphin:~# echo "`< probafile`" 1. sor 2. sor Arithmetic Expansion -------------------- $((expression)) examples: lencse@dolphin:~$ echo $((12*3)) 36 root@dolphin:~/test# echo $((2**(2,3))) 8 root@dolphin:~/test# echo $((2!=(a=3))) 1 (note: Arithmetic Evalution is done in long integers, operator precedence: C) Word Splitting -------------- IFS default is example, unlike in the earlier example: root@dolphin:~# echo E-mail:{Smith,Tailor}@ieee.org E-mail:Smith@ieee.org E-mail:Tailor@ieee.org Pathname Expansion ------------------ (note: the joker characters are different from the joker characters of the regular expressions) *, ?, [] special: starting dot, slash : matched explicitly examples: root@dolphin:~/test# ls 1*1 11 111 121 131 root@dolphin:~/test# ls 1[1,2]1 111 121 root@dolphin:~/test# ls 1[2-3]1 121 131 root@dolphin:~/test# ls 1[^2]1 111 131 -- root@dolphin:~/test# echo "one" > 1 root@dolphin:~/test# echo "dot one" > .1 root@dolphin:~/test# echo "ones" > 11 root@dolphin:~/test# ls * 1 11 root@dolphin:~/test# ls ?1 11 root@dolphin:~/test# ls .1 .1 lencse@vip:~/ta65$ echo "three ones" >111 lencse@vip:~/ta65$ mkdir 1 lencse@vip:~/ta65$ echo "file 'one' in the directory 'one'">1/1 lencse@vip:~/ta65$ ls 1?1 111 lencse@vip:~/ta65$ ls 1/1 1/1 Quote Removal ------------- \, ', " are removed (if they are unquoted/unescaped) (note: ' - single quote, " - double quote, / - slash, \ - backslash ) escape character '\' can be used... examples: root@dolphin:~/test# echo test\1 'test2' "test3" test1 test2 test3 root@dolphin:~/test# echo test\\1 test\'2 test\"3 test\1 test'2 test"3 lencse@vip:~/ta65$ echo "'" ' lencse@vip:~/ta65$ echo '"' " REDIRECTION =========== Standard I/O/Error: 0, 1, 2 file decriptors <, >, 2>&1 | >> <<[-] examples: lencse@dolphin:~$ ls -l egyik masik -rw-r--r-- 1 lencse users 20 Sep 15 19:01 egyik ---------- 1 lencse users 20 Sep 15 19:01 masik lencse@dolphin:~$ cat egyik masik egyik file tartalma cat: masik: Permission denied lencse@dolphin:~$ cat egyik masik 2>/dev/null egyik file tartalma lencse@dolphin:~$ cat egyik masik 1>x cat: masik: Permission denied lencse@dolphin:~$ cat x egyik file tartalma lencse@dolphin:~$ cat egyik masik 1>x 2>&1 lencse@dolphin:~$ cat x egyik file tartalma cat: masik: Permission denied root@dolphin:~/test# ls 11 111 121 131 root@dolphin:~/test# ls | sort -r 131 121 111 11 root@dolphin:~/test# ps -aux | grep ps root 336 0.0 0.3 2560 828 tty2 R 20:41 0:00 ps -aux root 337 0.0 0.1 1328 452 tty2 S 20:41 0:00 grep ps -- root@dolphin:~/test# echo 1st line > file root@dolphin:~/test# echo 2nd line >> file root@dolphin:~/test# cat file 1st line 2nd line root@dolphin:~/test# -- lencse@dolphin:~$ cat < 1st line > 2nd line > last line > EOF 1st line 2nd line last line lencse@dolphin:~$ -- root@dolphin:~/test# cat test cat <<- EOF an indented line EOF root@dolphin:~/test# ./test an indented line ALIASES ======= alias, unalias examples: lencse@dolphin:~$ alias alias d='dir' alias dir='/bin/ls $LS_OPTIONS --format=vertical' alias ls='/bin/ls $LS_OPTIONS' alias v='vdir' alias vdir='/bin/ls $LS_OPTIONS --format=long' CONDITIONAL EXPRESSIONS ======================= [ is a symbolic link to the 'test' command - file attribute check - string or arithmetic comparison examples: if [ -x /sbin/quotacheck ]; then echo "Checking filesystem quotas: /sbin/quotacheck -avug" /sbin/quotacheck -avug fi BASH kezelese ============= CRSR up/down TAB (1st pos, other pos...) recall: PATH Ctrl-R ! JOB CONTROL =========== suspend fg %1 bg %1 (% and its name [prefix] can be used too) %% or %+ last job %- previos job PROMPTING ========= PS1 primary prompt PS2 more imput is needed to complete the command examples: lencse@mmws:~$ PS1="szeretlek kedvesem! " szeretlek kedvesem! PS1='\u@\h:\w\$ ' lencse@mmws:~$ The normal prompt is restored. where:@: see the manual for more special characters inditaskori parancsfile-ok -------------------------- Ha a bash egy interaktiv login shell (pl. mikor belepek egy gepre), akkor: Eloszor, ha van, akkor vegrehajtja /etc/profile Utana ebben a sorrendben probalva az elsot (ami letezik es vegrehajthato) ~/.bash_profile, ~/.bash_login, and ~/.profile A user altal kiadott parancsok bekerulnek: ~/.bash_history Ha a bash login shell, mikor kilep, vegrehajtja: ~/.bash_logout Interaktiv, de nem login shell: ~/.bashrc Nem interaktiv shell: BASH_ENV-et kifejti, es azt hasznalja file-nevkent, de nem hasznalja a PATH-t... Fontosabb kornyezeti valtozok: ----------------------------- 1. amiket a bash hasznal: IFS PATH HOME MAIL/MAILCHECK/MAILPATH PS1, 2, (3,4) HISTORY, HISTSIZE HISTFILE, HISTFILESIZE 2. amiket beallit PWD, OLDPWD UID, EUID HOSTNAME for more, see: Shell Variables