What is the meaning of variable #,#,@,0,0,1,2,2,*,$$,$ in Linux?

Source: Internet
Author: User
Tags ord

12345678 $# is the number of arguments passed to the script $ 0   is the name of the script itself $ 1   $ 2   [email protected] is a list of all parameters passed to the script $* is to display all parameters passed to the script in a single string, unlike positional variables, which can exceed 9 $$ is the current process ID number for the script to run $? is the exit state that displays the last command, 0

Difference:@@*

  • Same point: All parameters are referenced
  • Different points: only in double quotes. Suppose that three parameters were written when the script was run (stored in1123) then " 3) "*" is equivalent to "1123"(Mass transferHandedThe one Ginseng number ) ;" 3 "(pass a parameter), and" @ "is equivalent to"1""1 "" 2 "" $ $ "(three parameters passed)

Example One

# #dels. Sh
echo "number:$#" echo "Scname:$0" echo "First:" echo "Second:$2" echo "Argume:[email protected]" echo "Show Parm list:$*" echo "Show process id:$$" echo "Show Precomm stat: $?"

Execution results

123456789 [@jihite]$ sh del.sh 123number:3scname:del.shfirst: 1second:2argume:123showparm list:1 23showprocess id:21057showprecomm stat: 0

Example Two

#!/bin/shnum=$ #name =$0echo "number: $num" echo "Scname: $name" echo $0echo $1echo $2for ((i=0; i< $num; i++)) do    Echo "$i" Doneecho "Argume:[email protected" "for key in [email Protected]do    echo $keydoneecho"-----------------"for key In "[email protected]" does    echo $keydoneecho "-----------------------------" for Key2 in $*do     echo $key 2doneecho " -----------------"for Key2 in" $* "Do     echo $key 2doneecho" show process id:$$ "Choecho" show Precomm stat: $? "

Execution results

12345678910111213141516171819202122 [@jihite]$ sh del.sh a b                                                      number:2scname:del.shdel.shab01argume:a bab-----------------ab-----------------------------ab-----------------a bshowprocess id:23582del.sh: line 37:cho: command not foundshowprecomm stat: 127

Problem:

echo #0 #1 can you use $i to express it?

Meaning of variable #,#,@,0,0,1,2,2,*,$$,$ in Linux

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.