Shell Summary (while)

Source: Internet
Author: User
#!/bin/bashwhile ifs=: Read name1 name2 name3 name4#ifs is the split symbol specified when reading from a file, assigning the contents of a to the corresponding variable in separate sections. Do echo $name 1 ' | ' $name 2 ' | ' $name 3 ' | ' $name 4 done <a# anti-quote and $ () function is command substitution, which will be executed as a command in the inverse quotation mark or the string in $ (), but the back quotation mark cannot continue to have the anti-quote, while $ () can have. ls= ' ls ' echo $LS # single quotation marks do not parse the command completely, ignoring all special strings and outputting them as strings. ls= ' ls ' echo $LS # Double quotation marks are similar to single quotes, except that it is not so strict that there are 3 special characters in double quotes that cannot be ignored: $,\, ', that is, single quotation marks will interpret the special meaning of the string, while single quotes are used directly. ls= "ls" echo $LS # But if you use the eval command, the commands in double quotes are interpreted. ls= "ls" eval "$LS" set--1 2 3 4 #设置参数, the same as the 2 parameters in main C. While [$#-GT 0]# $ #代表参数总数doecho $ #输出第一个参数shift 1 #将参数个数减1, and all move to 1 one bit, you can also set 2, move 2 bits at a time, equivalent to I--, i is the total number of parameters. DONE#-GT greater than #-lt less than #-ge greater than or equal to #-le less than or equal to #-eq equals #-ne does not equal # in the script can be used $1,$2 ... to accept parameters, but there is another way to accept parameters, that is getopts. While  getopts ABC opt #./main.sh-a-b-c can specify parameters and execute related commands docase $opt ina) echo "ABCD"; b) echo "1234";; c) echo "ABCD";; *) echo "* * * *"; Esacdone


Shell Summary (while)

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.