Shell note control structure if statement: Shell code #! /Bin/bashwww.2cto.com # if statement format: # Put if and then in different rows, and make the fi required for else and end align horizontally with them if [& quot; $ {1} & quot; & amp; #39; & amp; #39;] thenec...
Shell note control structure if statement: Shell code #! /Bin/bash www.2cto.com # if statement format: # Put if and then in different rows, and align the fi required for else and end with them horizontally if ["$ {1}" = ''] then echo no argument input. else echo first argument is: $1 fi var = 2 echo "$ {var}" if ["$ {var}" = "1"] then echo one. elif ["$ {var}" = "2"] then echo two. elif ["$ {var}" = "3"] then echo three. else echo at least four. fi for loop: Shell code #! /Bin/bash # The in keyword is followed by a word list, for x in one two three four do echo number $ x done for var in "$ @" do echo you pass in $ var done # use the file wildcard for myfile in/etc/r * do if [-d "$ myfile"] then echo "$ myfile is dir" else echo "$ myfile" fi done # You can also use multiple wildcards in the word list, even the variable # can use relative paths or absolute paths. for relative paths, bash executes wildcard extension relative to the current working directory. Www.2cto.com for x in./* var/lo */home/$ {USER}/* do echo $ x done while and until Loop: Shell code #! /Bin/bash echo use while loop control. myvar = 0 while [$ myvar-ne 10] do echo $ myvar = $ ($ myvar + 1) done www.2cto.com echo use until loop control. myvar = 10 until [$ myvar-eq 0] do echo $ myvar = $ ($ myvar-1) done
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