Linux commands (while, shell parameter usage), linuxshell

Source: Internet
Author: User

Linux commands (while, shell parameter usage), linuxshell

#! /Bin/bash while IFS =: read name1 name2 name3 name4 # IFS is the specified delimiter when reading content from a file: the separate parts are assigned to corresponding variables respectively. do echo $ name1 '|' $ name2 '|' $ name3 '|' $ name4 done <a # the function of anti-quotation marks and $ () is to replace commands, the string in the backquotes or $ () is used as a command for execution. However, the backquotes cannot be followed by backquotes, while $ () can. LS = 'LS' echo $ ls # The single quotes are not parsed at all. All special strings are ignored and output as strings are. LS = 'LS' echo $ ls # Double quotation marks are similar to single quotation marks. The difference is that they are not so strict. Three special characters in double quotation marks cannot be ignored: $ ,\,', that is, the single quotation marks explain the special meaning of the string, and the single quotation marks are used directly. LS = "ls" echo $ LS # However, if you use the eval command, the command in double quotation marks will be interpreted. LS = "ls" eval "$ LS" set -- 1 2 3 4 # set parameters, which are the same as the two parameters in main of c. While [$ #-gt 0] # $ # represents the total number of parameters do echo $1 # output the first parameter shift 1 # subtract 1 from the number of parameters and move one digit to 1, you can also set 2 to move 2 bits at a time, which is equivalent to I --. I is the total number of parameters. Done #-gt is greater than #-lt is less than #-ge is greater than or equal to #-le is less than or equal to #-eq is equal to #-ne is not equal to #$1 can be used in the script, $2... to accept the parameter, but there is another way to accept the parameter, that is, getopts. While getopts abc opt #. /main. sh-a-B-c can specify the parameter and then execute the related command do case $ opt in a) echo "abcd"; B) echo "1234"; c) echo "ABCD"; *) echo "*****"; esac 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.