Learning notes: [$*],[$@] and [$#] in a shell script [$?] [$] [$] [$] [$!] ... What do you mean, separately?

Source: Internet
Author: User
For example, the
script name is called test.sh Three: 1 2 3 is as follows
./test.sh 1 2 3  
After running test.sh 1 2 3
$* is "1 2 3" (enclosed in quotes)
$@ is "1" "2" "3" (wrapped separately)
$ #为3 (number of parameters)
Case 2:
#!/bin/bash 
My_fun () { 
    echo "$#" 
} 
Echo ' The number of parameter in ' $@ ' is ' $ (my_fun "$@")    
Echo ' the Number of parameter in ' $* ' is ' $ (my_fun ' $* ')
Execution:./my.sh p1 "P2 P3" P4 after return:  
The number of parameter in "$@" are 3      //"$@" = "P1" "P2 P3" "P4" the number of

parameter in "$*" is 1     //"$*" = "P1 P2 p3 P4"
$n
The first parameter is represented, and the second parameter is $ ...

$#
Number of command line arguments

$
The name of the current program

$?
The return code of the previous command or function

$*
With the parameter 1 parameter 2 ... Save all parameters in the form

$@
With the parameter 1″ parameter 2″ ... Save all parameters in the form

$
PID for this program (process ID number)

$!
PID of the previous command
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.