Shift: causes the number offset of the parameter variable.

Source: Internet
Author: User

Can the variables followed by the script be shifted? What is offset? Let's explain it directly using the following examples. It is better to explain it with examples!

#! /Bin/bash
Echo "Total Parameter number is ==>$ #"
Echo "your whole parameter is ==> '$ @'"
Echo-e "You'll shift one num, please wait... \ n"
Shift
Echo "Total Parameter number is ==>$ #"
Echo "your whole parameter is ==> '$ @'"
Echo-e "You'll shift 3 num, please wait... \ n"
Shift 3
Echo "Total Parameter number is ==>$ #"
Echo "your whole parameter is ==> '$ @'"

Execution result:

[Oracle @ sor_sys ~] $Sh shift. Sh one two three four five six
Total Parameter number is => 6
Your whole parameter is ==> 'one two three four five six'
You'll shift one num, please wait...

Total Parameter number is => 5
Your whole parameter is ==> 'two three four five six'
You'll shift 3 num, please wait...

Total Parameter number is => 2
Your whole parameter is ==> 'five six'

You can see the result. Shift will move the variable, and shift can be followed by a number, which means to remove the first few parameters. In the preceding running result, after the first shift operation, the displayed information is "one
Two three four five six ", so there are five left! If you remove three of them for the second time, it will become "two three four five six! Can this case be understood? Have you understood the shift function?

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.