Shell (7) User 2.16.doc

Source: Internet
Author: User
Command line parameters,
Positional Parameter

$0
Complete program name
(Basename
Command to remove the path
)

$1
The first parameter, exceeding
9
Hour
$ {10}

$ #
Number of parameters

$ *
All parameters in the command line, as a word

$ @
All parameters in the command line, used as multiple words

$
Current
Shell
Of
PID

$-Shell
Some attributes

$!
The previous background process
PID

 

Echo
'Basename $0'
#

Obtain the program name

Echo
$ {! #}


#

Obtain the last parameter

For (I = 1;
I <=$ #; ++ I); do
#

Traversal Parameters


Echo $ {! I}
#{}

Cannot be used
$

, Available
!

Substitution

Done

For
In $ @; do


#

Another Traversal method,
$ @

Change
$ *

Yes.


Echo $

Done

 

Shift
Command

Change the relative position of the command line parameter. The default value is left.
1
Bit, that is
$3
Change
$2
,
$2
Change
$1
,
$1
Discarded

Eg:
Another method for Traversing Parameters

While
[-N "$1"]; do


Echo $1


Shift

Done

 

Getopts
Analysis parameters

 

Read
, Get user input

Read


#
Read to variable
$ Reply
Medium

Read name
#
Read
Name

Read-P "input your name:" Name
#
With prompt
Read

Read name age

#
Read multiple variables separated by Spaces

Read-T 5 Name

#
Wait
5
Seconds, return failure

If
Read-T 5 name, then

Read
-N1-P "input [Y/n]" answer

#

Set the number of characters to read-read a single character, so that you do not need to press enter, in
Emacs

But the terminal can

Read
-S-p "input PWD" pwd

#

Do not show input,
Emacs

But the normal terminal can

 

Read
, Read files

Read once
1
Line, cannot directly take the file name as the parameter, you need to use
Cat
And other commands

Cat
A.txt | while read line
# Read

A redirected application?

Do


Echo $ line

Done

 

Output

Printf "format" A1 A2...

Eg:
Printf "af 0x % x" 11
#

Same format Controller
C

 

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.