A simple example of shell-pass arguments

Source: Internet
Author: User
Description: The shell parameter, as the name implies, is passed to the shell script, we can use some parameters in the sh scripts.sh parameter parameter +1 parameter +2 of the way to execute.
The format for getting parameters within a script is: $n n represents a number,
The first argument to execute script (corresponding to the above parameter)
$ $ is the second parameter to execute a script, and so on ...

Here's a simple chestnut:

1. First edit a simple script, as follows:
[Email protected] 01]# vim 1.sh

#!/bin/bash
echo "I am $1,you is."

2. Execute the following script
[[Email protected] 01]# sh 1.sh
I am, you is.
[email protected] 01]# cat 1.sh
#!/bin/bash
echo "I am $1,you is."

3. Add the corresponding parameters behind the script
[Email protected] 01]# sh 1.sh Lili Leilei
I am Lili,you is leilei.

The shift command shifts the positional parameters to the left with the shift command.
For example, the Shift 3 command will now change the original $4 to $
Will turn the original $ $ now into a $ $ and so on,
will be the original $, $, $ discarded, no move.
The shift command with no parameters is equivalent to shift 1.

A simple example of shell-pass arguments

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.