Special variables in the shell $ $ $# $$ $! $? meaning __shell Script

Source: Internet
Author: User
$: The name of the executing script $* and $@: Return all parameters to $#: The number of arguments $_: represents the last parameter of the previous command $$: The PID $! that represents the command that was last executed: The PID $?: A flag that represents the success of the previous command, or $ if the execution succeeds? is 0, otherwise not 0.
Write a script test [wang@localhost desktop]$ vim test1.sh #!/bin/sh echo number:$# "echo" Name:$0 "echo" first:$1 "echo" Secon D:$2 "echo" argure1:$@ "ret=" $@ "ret1=$@ echo" $ret "echo" $ret 1 "echo" argure2:$* "echo" Arg:$_ "echo" result:$ "echo" P Id:$$ "echo" pid:$! "
[Wang@localhost Desktop]$ chmod +x test1.sh [wang@localhost desktop]$ ./test1.sh a b c number:3 Name:./test1 . SH first:a second:b argure1:a b c A b c a b c Argure2:a b c Arg:argure2:a b c result:0 pid:14973 PID:
[Wang@localhost Desktop]$ ./test1.sh "A" "B" "C" except the PID is not the same, the other results are the same.
After testing, the following doubts were expressed: $*: Give the argument list in double quotes $@: Return each argument with double quotes
Note: The meaning of the $ $ is different in the shell and awk. Shell: First word of the command line awk: current record


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.