Linux Shell Basics (vii)

Source: Internet
Author: User

Vii. Process Control   conditional judgment control in bash Scripts   [] (the expression in [] is true)  && (the result of the front is true when executing the command behind)   | | (The result of the front is false when executing the command behind)  -if -case  loop control  -while -utile -for -break - continue#[ABC] #echo $?0 (for true) #[] #echo $?1 (for false) #["$USER" = "BYF" [The Meaning of ' $?* ' is to remove the special meaning of the character, "" The double quotation marks only remove the special meaning of the space) #echo $? 1#[$USER = root] #echo $?0#[$USER = root] && echo Hello Roothello root#[-x/etc/] && echo Hellohello#man Bash input/-w to find, n Find Next #-r (Read)-W (write)----------------------------------(link)-B (Block's adapter file)-c#[-b/dev/hda]&& echo You ha ve a IDE DEVICE#[-B/DEV/SDA]&& echo you have a SCSI deviceyou has 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 of Here ' fiwq#./b#bash-v./b (see Execute to that command) #bash-VX./b (view error command line, For debugging, you can see the value of each variable) c and bash debug the difference c is a pure binary file, debugging requires the corresponding development environment settings Breakpoint Bash isText files that can be directly detected where the error is ##! /bin/bashread Aaacase $ (Take out the value of the variable) AAA inBYF)echo Hello ByfEcho Nice to meet;;( Indicates end)Root)echo Hello Rootecho I miss much;;* )Echo Get out Here;; Esac:wq#bash./cbyf-eq = Same-ne! = Different-gt >-lt <-ge >=-le <=-z is empty #!/bin/bashaaa= "' pgrep httpd '" [-Z "$AAA" ("3186 3188 3189 3190 3191 3192 3193 319 4 3195 "Remove the space 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 ' doEcho $aaa; Sleep 1 (Semicolon does not add carriage return, no semicolon added line)(Echo-n "$AAA"Sleep 1) done##!/bin/bashiii=0while [$III-lt 100]Doi=$[$IIII +1]Echo-n "$III"Done##!/bin/bashiii=0until [$III-GT 100]Doiii=$[$III +1]Echo-n "$III"Doneunset Iii:wq##!/bin/bashwhiletrue DoRead AAAIf ["$AAA" = "ddd"]ThenBreakFidone

Linux Shell Basics (vii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.