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

Source: Internet
Author: User

for these things, the gods are already in the chest, but there are some just contact Linux , Unix people like these systems may not be familiar with these variables, so I'll share them with you today. What problem can add QQ Group, we discuss together -- Ops tribe:348384728


To make it easier for everyone to understand, write a simple script that will explain the meaning of each variable later.

# Touch Test

# VI Test

The script reads as follows:

#!/bin/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: $?"

Save exit

Assigning script execution Permissions

# chmod +x Test

Execute script

#./test AA BB

Number:2
Scname:./test
First:aa
Second:bb
ARGUME:AA BB

Show Parm LIST:AA BB
Show Process id:24544

Show Precomm stat:0

By displaying the results you can see:

$#  is the number of arguments passed to the script

$ is the name of the script itself

$ is passed to the Shell the first parameter of a script

$ is passed to the Shell The second argument of a script

[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, where parameters can exceed 9 a

$$  is the current process that the script runs ID number

$?  is to display the exit status of the last command, 0 indicates no error, other indicates an error


This article is from "Old Gao Blog" blog, please be sure to keep this source http://12092502.blog.51cto.com/12082502/1943049

Linux variable $#,[email protected], meaning of $0,$1,$2,$*,$$,$?

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.