Summary of several special shell variables in Linux

Source: Internet
Author: User

 

########################

Summary of several special shell variables:

########################

######################################## ####################

#

# Http://hi.baidu.com/xece/modify/blog/75327e382149dae23b87ce5a

######################################## ####################

Special shell variables:

$0 get the name of the currently executed shell script

$ N obtain the nth parameter value of the currently executed shell script, n = 1 .. 9

$ * Get all parameters of the current shell "$1 $2 $3... Note the difference with $ #

$ # Obtain the total number of parameters in the Current Shell Command Line

$ Obtain the current shell process ID (PID)

$! PID used to execute the previous command

$? Obtain the returned value of the previous Command executed (0 indicates success, and non-zero indicates failure)

$ @ All parameters of this program "$1" "$2" "$3" "…"

Example ):

[Ryan @ etiantian test] # Cat etiantian. Sh

Echo '$0 get the name of the currently executed shell script:' $0

Echo '$ n get the nth parameter value of the currently executed shell script, n = 1 .. 9: ''$ 1' = $ 1' $ 2' = $2 '\ $3 = $3 ″

Echo '$ * Get all parameters of the Current Shell' $1 $2 $3... Note the difference with $ #: '$ *

Echo '$ # obtain the total number of parameters in the current shell command line:' $ #

Echo '$ obtain the current shell process ID (PID):' $

Sleep 2 &

Echo '$! PID for executing the previous command: '$!

Echo '$? Obtain the returned value of the previous command: '$?

Echo '$ @ all parameters of this program "$1" "$2" "$3" "…" : '$ @

Script Execution results (carefully read ):

[Ryan @ etiantian test] # sh etiantian. Sh parameter 1 parameter 2 parameter 3

$0 get the name of the currently executed shell script: etiantian. Sh

$ N get the nth parameter value of the currently executed shell script, n = 1 .. 9: $1 = parameter 1 $2 = parameter 2 $3 = parameter 3

$ * Get all parameters of the current shell "$1 $2 $3... Note the difference with $ #: parameter 1 parameter 2 parameter 3

$ # Obtain the total number of parameters in the current shell command line: 3

$ Obtain the current shell process ID (PID): 2062

$! PID for executing the previous command: 2063

$? Obtain the returned value of the Last Command executed: 0

$ @ All parameters of this program "$1" "$2" "$3" "…" : Parameter 1 parameter 2 parameter 3

[Ryan @ etiantian test] # sh etiantian. Sh Ryan jeacen David

$0 get the name of the currently executed shell script: etiantian. Sh

$ N get the nth parameter value of the currently executed shell script, n = 1 .. 9: $1 = Ryan $2 = jeacen $3 = David

$ * Get all parameters of the current shell "$1 $2 $3... Note the difference with $ #: Ryan jeacen David

$ # Obtain the total number of parameters in the current shell command line: 3

$ Obtain the current shell process ID (PID): 2160

$! PID for executing the previous command: 2161

$? Obtain the returned value of the Last Command executed: 0

$ @ All parameters of this program "$1" "$2" "$3" "…" : Ryan jeacen David

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.