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

Source: Internet
Author: User
Tags ord

$# 是传给脚本的参数个数$0是脚本本身的名字$1 是传递给该shell脚本的第一个参数$2是传递给该shell脚本的第二个参数[email protected] 是传给脚本的所有参数的列表$* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过9$$ 是脚本运行的当前进程ID号$? 是显示最后命令的退出状态,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

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.