Special variables in the shell ($ A, $#, $*, $@, $$, $!, $, $1~ $n)

Source: Internet
Author: User

In the shell, $* and [email protected] respectively represent the following meanings:

$ A: The name of the script itself

$#: Number of positional parameters

$*: All positional parameters will be treated as a string

[Email protected]: Each positional parameter is considered a separate string

$$: PID of the current process

$! : The PID of the last daemon run by the shell

$?  : Returns whether the last command was successful, 0 indicates successful execution, and not 0 indicates execution failed

$1~ $n: each parameter value added to the shell. $ $ is the 1th parameter, and the $ = is the 2nd parameter ....


Example:

#!/bin/bashecho "The name of this shell script is: $" echo "first param is:" echo "Second param is: $" echo "third param is: $ "echo" The total number of param are: $# "for I In" $* ";d o echo $idonefor n in" [email protected] ";d o echo $n Doneecho "The PID of current process: $$" echo $!


Test results:

[[email protected] ~]# bash var_1.sh a b cthe name of this shell script is:var_1.shFirst param is:asecond param is:bthi RD param is:cthe Total number of param is:3a b cabcthe PID of current process:20022[[email protected] ~]# echo $?0



The difference between $* and [email protected]:


As can be seen from the test results, $* is the use of all positional parameters as a string input, while [email protected] is to use each positional parameter as a separate string output.

This article is from the "Running Snail" blog, please make sure to keep this source http://441274636.blog.51cto.com/5054639/1890303

Special variables in the shell ($, $#, $*,[email protected], $$, $!, $, $1~ $n)

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.