In the shell, we can use $ A, $, $, $ ... This variable extracts the variables in the command line

Source: Internet
Author: User

Code: Script_name parameter1 parameter2 Parameter3 ...
It's easy to guess that the $ A is the shell script name (path) itself, and $ $ is the first argument, and so on ....

you have to pay attention to the role of IFS, that is, if IFS is quoting, then Positionalparameter will change.
The following example:
code: my.sh P1 "P2 p3" p4
Fucntion, I didn't say it was script in script

< Span style= "color: #008000;" The exception is $ A.

For example: There is a fucntion called My_fun in my.sh, if you run My_fun FP1 fp2 in script, FP3 pan>
Then, the function of the $ is my.sh, and that is FP1 rather than P1 ...

code: #!/bin/ Bash

My_fun () {

Echo ' $ inside function is ' $

Echo ' inside function is ' $

Echo ' $ inside function is ' $

}

Echo ' $ outside function is ' $

Echo ' outside function is ' $
Echo ' $ outside function is ' $

My_fun FP1 "FP2 fp3"

Then run the script in command line to find out:
Code: chmod +x my.sh./my.sh p1 "P2 p3"

$ outside function is./my.sh

$ outside function is P1

$ outside function is P2 p3

$ inside function is./my.sh

$ inside function is FP1

$ inside function is FP2 FP3


We often use the following method in the shell script to test if the script has read parameters:
Code:
if [$# = 0] //See not, all the contents of [] must have spaces in parentheses
If it is 0, it means that the script does not have a reference, or that it has a number of parameters ...

In the shell, we can use $ A, $, $, $ ... This variable extracts the variables in the command line

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.