shell--special position parameter variables and common built-in variables

Source: Internet
Author: User
Tags shell script arguments

Special positional parameter variables in 1.shell

$: Gets the file name of the currently executing shell script, including the script path if the execution script contains a path

$n: Gets the nth parameter of the currently executing shell script, n=1..9, which represents the file name of the script when n is 0, or if n is greater than 9, enclosed in curly braces

For example ${10}, the parameters are separated by a space

$#: Gets the total number of parameters that are followed by the currently executing shell script

$*: Gets the arguments of all parameters of the current shell script, without quotation marks and [email protected], if the $* with double quotes, such as "$*", it means that all parameters are treated as

As a single string, equivalent to "$ $ $"

[Email protected]: Get all parameters of the current shell script arguments, without quotation marks and $* the same, plus double quotes, such as "[email protected]", it means that all the parameters are treated as a different

Independent string, equivalent to "$" "$" "$" "..." This is the best way to pass multiple parameters to other programs because it preserves all inline

Any whitespace in each parameter.

Special state variables in the 2.shell process

$?: Gets the execution state return value that executes the last instruction (0 for success, not 0 for failure), commonly used

$$: Gets the process number (PID) of the currently executing shell script, not commonly used

$!: Gets the process number (PID) of the last process working in the background, not commonly used

$_: Gets the last parameter of the command or script executed before this, not commonly used


3.bash shell built-in variable command

The bash shell contains some built-in commands. These built-in commands are invisible in the table of contents and are provided by the shell itself. The common internal commands are:

Echo, eval, exec, export, read, shift.


Echo: Output information on the screen

Command format: Echo args

Parameters:

-N: Do not wrap output content

-E: Parsing escape characters

Escape characters:

\ n: Line break

\ r: Enter

\ t: Tab (TAB)

\b: Backspace

\v: Portrait tab


Eval:

Command format: eval args

Function: When the shell program executes to the Eval statement, the shell reads the parameter args, combines them into a new command, and then executes


Exec:

[Email protected] script]# vim exec.sh

[email protected] script]# cat exec.sh

#!/bin/bash

EXEC </script/1.txt

While Read line

Do

Echo $line

Done

Echo OK

[[email protected] script]# SEQ 5 > 1.txt

[email protected] script]# cat 1.txt

1

2

3

4

5

[Email protected] script]# sh exec.sh

1

2

3

4

5

Ok


This article is from "It look" blog, please be sure to keep this source http://jinlong.blog.51cto.com/3276088/1954810

shell--special position parameter variables and common built-in variables

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.