"Shell script Learning" shift command learning

Source: Internet
Author: User
Positional parameters can be moved left with the shift command. For example, shift 3 means that the original $ $ is now $, the original $ $, and so on, the original $ $, $ $, $ $ no move. The shift command with no parameters is equal to shift 1.

Very useful Unix command: Shift. We know that for positional variables or command-line arguments, the number must be fixed, or when the Shell program does not know its number, you can assign all the arguments to the variable $*. If the user requires that the Shell does not know the number of position variables, can also be one by one of the parameters of one by one processing, that is, after $ $ $, in the back of $ $. The value of the variable before the shift command executes is not available after the shift command executes.

The test commands are as follows:

root@wl-ms-7673:/home/wl/Desktop/shell# cat-n test.sh
     1	#shift command (x_shift.sh)
     2	until [$#-eq 0]
     3	The first parameter of Do 4 echo is: $# "
     5	shift
     6 done
root@wl-ms-7673:/home/wl/Desktop/ shell# 

The output results are as follows:

root@wl-ms-7673:/home/wl/Desktop/shell# chmod u+x test.sh root@wl-ms-7673:/home/wl/ 
desktop/shell#./test.sh a b c d E F g
  

  

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.