Shift command in Shell

Source: Internet
Author: User

Okay. Run this script and you will understand it.

#! /Bin/bash Until [ $ #-EQ 0] Do Echo "$ @" Shift Done

See the role. When shift (without parameters) is run each time, a parameter is destroyed and the subsequent parameter is moved forward.
Output:

YY-QS :~ #./Test. Sh 1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10
5 6 7 8 9 10
6 7 8 9 10
7 8 9 10
8 9 10
9 10
10

The number of moving parameters at a time is specified by the parameter included in the shift command. For example, whenProgramAfter processing the first nine command line parameters, you can use the shift 9 command to move $10 to $1.
Important: Bash defines nine location variables, from $1 to $9. This does not mean that you can only use nine parameters in the command line, you can use the shift command to access more than 9 parameters.

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.