The use of $ in a shell script

Source: Internet
Author: User
Tags parent directory
$: The script name, relative path, or absolute path depends on how the call is being invoked. If the./dollartest.sh call is in the parent directory, then $ is./dollartest.sh, if it is a full path call, such as "/root/test/dollartest.sh", then $ is "/root/test/     Dollartest.sh ". $n: The nth argument of the invocation.     PS: If n > 9, the number needs to be enclosed in parentheses, such as ${10}, otherwise the shell interpreter would think that the number is $1.     $*: All parameters in the script. $@: With $*.
$#: The number of parameters for the script.     $$: Change the process number when the shell script executes.     $?: The output of the previous command, if the return value of the previous command exit.     $!: The PID number that was executed by the previous background process.!$: Last string of previous command. $-: The flag set by using the SET command.
To run the script dollartest.sh, for example, script code:
#!/bin/bash Echo ' $ is ' $ ' is ' $ ' ' is ' ' $11 ', ' is ' ' The Echo ', '
${11}
Echo ' $# is ' $#
echo ' $* is ' $*
 echo ' $@ is ' $@
echo ' $$ are ' $$
sh test.sh    # This shell script'll exit with one
Echo ' $ is ' $?
 echo ' $# is ' $#
nohup ping www.baidu.com &
Echo ' $! is ' $!
Echo $-
Because there are special characters, display is not complete, so use the picture display shell source code;

Run commands and Parameters:./dollartest.sh 1 2 3 4 5 6 7 8 9 10 21 22 23 24 Execution Results:

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.