Shell processing input

Source: Internet
Author: User

1, when the script is run to specify parameters, directly behind the script name to follow the parameters to be added, in the process of running, "$" represents the program name, "$" represents the first parameter, the second parameter, the Nineth, from the tenth parameter needs to become a ${10}, such as the need to add curly braces. In the program, $ #可以返回所有参数的个数, however, this does not mean that the last parameter can be obtained by ${$#}, actually obtaining the format of the last parameter to be ${!#}.

2, in the process of running, you can get all the parameters in different ways, $* will read all the parameters and the parameters as a parameter, and [email protected] will save each parameter, so that each value can be traversed in the program, such as:./test a B In the process of running, [email protected] is equivalent to an array, length is 2, and #* is equivalent to one parameter.

3, move the variable through shift, in the program, starting with the first argument, each shift one, the current resulting parameter will become the next, until each parameter is traversed, and through the "shift number" way can specify the step. Such an operation will result in a change in the total parameters obtained in the program.

4, you can enter parameters in the process of running the program, through read, the options for this parameter are as follows:

1)-P, followed by a hint, if you join-p but did not join the prompt, it will cause the first parameter after-P is used as a prompt;

2)-T, followed by a number, indicating the number of seconds to timeout;

3)-S, will hide the input characters;

Read in the process of running, you can specify a number of parameters to enter values, if the number of input parameters is greater than the number of parameters given, then the excess will be all assigned to the last parameter, and if the input parameters are not enough, it will result in the extra input parameters are all empty.

5, can also use channels, such as Cat a | While read lines, which means reading the data of a file and entering each line into the program.

Shell processing input

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.