Introduction to process state variables for special variables in shell programming _linux shell

Source: Internet
Author: User

Process state variables

1, $$ get the current shell process number (PID)
2, $! executes the PID of the previous instruction
3, $? Gets the return value that executes the previous command (0 is a success, Non-zero is a failure, this is very common)
4. $_ the last parameter of a command or script executed before this

Copy Code code as follows:

Cat> test$.sh
Echo ' $$= ' $$
Echo ' $!= ' $!
Echo ' $?= ' $?
Echo ' $@= ' $@
Echo ' $_= ' $_
#输出如下
SH test\$.sh 1 2 3
$$=2556
$!=
$?=0
$@=1 2 3

The difference between $* and $@

$* treats all parameters as a single string, equivalent to "$1$2$3"
$@ treats each parameter as a single string, preserving any whitespace characters in the command line

Copy Code code as follows:

set--' I am ' Jane Lee
Fori in$*; doecho$i; Done
I
Am
Jane
Lee
Fori in$@; doecho$i; Done
I
Am
Jane
Lee
Fori in "$@"; doecho$i; Done
I am
Jane
Lee
Fori in "$*"; doecho$i; Done
I am Jane Lee

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.