In Linux, the input parameters are output cyclically as follows: execute a loop based on the number of script parameters $ #, and output each parameter $1 $2 $3 in sequence ...... I have a loop variable I $ I to get the I as 1 at this time. I want to use this 1 and then call $1, that is, print out the first parameter $ ($ I... in Linux, the input parameters are output cyclically as follows: execute a loop based on the number of script parameters $ #, and output each parameter $1 $2 $3 in sequence ...... I have a loop variable I $ I. When I get this variable I is 1, I want to use this 1 and then call $1, that is, print out the first parameter $ ($ I) of course, $ ($ I) is not useful. Method 1 :#! /Bin/shNUMBER =$ # echo $ NUMBERi = 1 while [$ I-le $ NUMBER] doa [$ I] = $1 # assign an array a [I] to $1, that is, the first parameter is obtained and the value is saved to a [1] echo $ {a [$ I]} (I ++) # The array is removed by one digit, change to a [2] shift # use the shift command to move the parameter one bit behind, that is, $1 is the second parameter done. Method 2 :#! /Bin/bash a = ($ @) # obtain all parameters from $ @ and save the parameters to a for I in $ {a [@]}; do # loop echo $ I done using I in each parameter
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