Variables of Shell programming

Source: Internet
Author: User

Variable:

A variable is made up of letters, numbers, and _, and cannot begin with a number

Length cannot exceed 255 characters

In bash, the default type of a variable is a string type

Variable classification:

1, user-defined variables: only in the current shell to take effect, is a local variable

Definition method: Variable name = variable Value #等号两边没有空格

Calling method: $ variable Name

Variable view: Set command to view all variable options:-u #如果设定此选项, error when calling undeclared variable Yes (default no hint)

Delete variable: unset variable name

Variable overlay: x=${x}test or x= "$x" test

2. Environment variables: This variable mainly holds the data related to the system operating environment. Variables can be customized, but the environment variable names and variables that are valid for the system are fixed, in effect in the current shell and child shell, and are global variables

Definition method: Environment variable name recommended capitalization

Export variable name = variable Value

or variable name = variable value; Export variable Name

View method: Env View Environment variables

Delete: can only be removed in the shell that created the variable

Common environment variables:

HOSTNAME Host Name

Shell Current Shell

Term terminal environment

Histsize History Command bar number

Ssh_client Log SSH Client IP

Ssh_tty SSH-connected terminals

User Current Login

Path System Search Command

3, positional parameter variables: one of the predefined variables, mainly used to pass parameters or data to the script (in fact, the use of Read commands to replace, after the mention), variable names can not be customized, variable role fixed

$n written in the script, the role is to pass data into the script, such as:/root/calcu.sh 32 13, where the/root/calcu.sh,32 represents the $1,13 on behalf of the $

4. Predefined variables: is a variable that is already defined in bash, the variable name cannot be customized, and the variable function is fixed

$$ process Number of the most recent process

Receive keyboard input

    • Read "option" "Variable name" #多用于脚本中接收用户输入

Options:

-P "prompt message" #在等待read输入时, output this prompt message

-T number of seconds #read命令会一直等待用户输入, this option to specify the wait time

-N Character Count #read命令只接收指定的字符数, automatically executed upon receipt

-s #隐藏输入的数据 for input of confidential data

Variables of Shell programming

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.