Shell note control structure

Source: Internet
Author: User


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

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.