Linux shell BASICS (7) and Linux shell Basics
VII. Process Control Condition judgment control in the bash script-[] ([] expression is true) & (execute the following command when the result of the front side is true) | (if-case loop control-while-utile-for-break-continue # [abc] # echo $? 0 (true) # [] # echo $? 1 (false) # ["$ USER" = "byf"] ('$? * 'Indicates removing special characters. "" Double quotation marks only remove the special meaning of spaces.) # echo $? 1 # [$ USER = root] # echo $? 0 # [$ USER = root] & echo hello roothello root # [-x/etc/] & echo hellohello # input/-w in man bash to search, n find the next #-r (read)-w (write)-x (executable)-f (common file)-d (whether a directory exists)-L (Link) -B (block adaptation file) -c # [-B/dev/hda] & echo you have a ide device # [-B/dev/sda] & echo you have a scsi deviceyou have a scsi device # [-f/usr/sbin/httpd] & echo please install httpt againplease install httpd again # vi B #! /Bin/bashread AAAif [$ AAA = byf] thenecho hello byfelif [$ AAA = root] thenecho hello rootelse echo 'Get out here 'fiwq #. /B # bash-v. /B (see the Command executed) # bash-vx. /B (view the error command line for debugging, you can view the value of each variable) C and bash debugging difference C is a pure binary file, debugging requires the corresponding development environment to set a breakpoint where bash contains text files. errors can be detected directly ##! /Bin/bashread AAAcase $ (get the variable value) AAA inbyf) echo hello byfecho nice to meet you; (indicating the end) root) echo hello rootecho I miss you so much ;; *) echo get out here; esac: wq # bash. /cbyf-eq = same-ne! = Different-gt>-lt <-ge> =-le <=-z is blank #! /Bin/bashAAA = "'pgrep httpd '" [-z "$ AAA" ("3186 3188 3189 3190 3191 3192 3193 3194" Remove spaces in the variable)] & echo httpd 'httpd is not running! '& Exitfor I in $ AAAdokill-9 $ idoneecho httpd is killedwq # chmod a + x d #./d #./d #! /Bin/bashfor aaa in 111 222 333/etc/profile. d /*. hdoecho $ aaa (chmod a + x $ aaa batch operation) done # chmod a + x e #. /e111222333/etc/profile. d/colorls. sh/etc/profile. d/glib2.sh/etc/profile. d/gnome-ssh-askpass.sh/etc/profile. d/kde. sh/etc/profile. d/lang. sh/etc/profile. d/less. sh/etc/profile. d/qcd. sh/etc/profile. d/qt. sh/etc/profile. d/udisks-bash-completion.sh/etc/profile. d/vim. sh/etc/profile. d/which2.sh # seq 1 10012 ...... 100 #! /Bin/bashfor aaa in 'seq 1 100 'doecho $ aaa; sleep 1 (semicolon without carriage return, line feed without extra points) (echo-n "$ aaa" sleep 1) done ##! /Bin/bashiii = 0 while [$ iii-lt 100] doi = $ [$ iiii + 1] echo-n "$ iii" done ##! /Bin/bashiii = 0 until [$ iii-gt 100] doiii = $ [$ iii + 1] echo-n "$ iii" doneunset iii: wq ##! /Bin/bashwhiletrue doread AAAif ["$ AAA" = "ddd"] thenbreakfidone