Bash Shell's parametric symbolic meaning

Source: Internet
Author: User
Tags command line regular expression

Some arguments are used in the Bash Shell,

$1,$2,... A specific number of parameters, the name of the currently executing process name, the script itself, or the whole row output in a regular expression

$# the command line or the number of positional arguments

$* all positional parameters, being used as a word.

$@ is synonymous with $*, but each argument is a separate "" reference string, which means that the parameter is passed in full

$-passed to the script Falg

$! The PID (process ID) of the last work running in the background.

$_ the last parameter of the command that was executed before it was saved.

$? function, or the exit state of the script itself, to check whether the previous command, function, or script was executed correctly. (0 indicates that the command executes correctly, and any non-0 value indicates a command error.) )

$$ The process ID of the script itself.
Use examples:
Execute statement Run Result:

[Root@myhost tmp]#./filelist.sh file1.txt file2.txt file3.txt General
file list Files:3 general by
:./filelist. SH Last
command:last PID: are
normal:0 current
pid:26418

Filelist.txt:

[Root@myhost tmp]# cat filelist.txt
Param1:file1.txt
Param2:file2.txt all
param:file1.txt file2.txt File3.txt all
param:file1.txt file2.txt file3.txt
FLAG:HB last
PID:

filelist.sh

[Root@myhost tmp]# cat filelist.sh
#!/bin/bash
    
echo General file List files: $# '
    
echo ' General by: $ "
    
E Cho "Param1: $ > Filelist.txt
echo" PARAM2: $ >> filelist.txt
    
echo "all param: $*" >> filelist. TXT
echo "All param: $@" >> filelist.txt
    
echo "Flag: $-" >> filelist.txt
echo "Last PID: $!" >& Gt Filelist.txt
    
echo "Last command: $_"
echo "is normal: $?"
echo "Current PID: $$"

This article from the "Small Hebebe Technical Space" blog, please be sure to keep this source http://babyhe.blog.51cto.com/1104064/322297

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/unix/

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.