Shell Script--shift parameter left

Source: Internet
Author: User

What does it mean to move the parameter left? This parameter refers to the arguments that follow the script name when you run the script, you can use the $ #来获取参数的个数, use $* to get all the arguments, and the left side of the argument is this: there is a pointer to the first parameter of the parameter list, and the left shift means that each argument is read, The pointer points to the second parameter, as if the parameter were moved to the left, so that the value of each parameter can be read, which is especially common in the loop structure.

Here's an example:

#!/bin/bash# file name: test.shtot=0while [$#-gt 0]do    echo ' parameter is ' $  #注意这里使用 ' to get the parameter value    tot=$ (($tot + 1))    shift< c5/> #注意如果不使用shift时, there will be a dead loop done    echo "altogether $tot parameters"

To run the test:


  

Shell Script--shift parameter left

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.