Tips for getting parameters from shell scripts

Source: Internet
Author: User
The problem is as follows: perform 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.
After a long struggle at that time, I finally asked hundreds of questions. The two experts gave the answer:
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, in this case, $1 is the second done parameter, and the data in the array a [Key] contains the number of keys in $ {A [Key]}. For example: the value of a [1] is $1.

Of course, the first method is not usable for me.


2)

#! /Bin/Basha = ([email protected]) # obtain all parameters from [email protected] and save the parameters to afor I in $ {A [@]}; do # loop echo $ idone using I in each parameter


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.