LINUX_10------Linux Shell programming------variables

Source: Internet
Author: User


Shell programming is designed to simplify management operations。

1、base variable and variable classification
base is the standard shell for Linux。

Base Variable
Set:querying all environment variables under the system
Env: view environment variables under system
unset:Delete a variable
a.What are variables and variable categories
The variable starts with a letter and an underscore,Consists of a letter underlined number。
the variable name does not exceed 255 characters in length。
The variable name must be unique within the valid range。
in base,The default type of a variable is a string type。
variables are categorized by storage data type:String Type、Integral type、floating Point Type、Date Type。
Classification of variables:
user-defined variables,variables are custom-defined;
Environment Variables,data that is relevant to the operating environment of the system is saved;However, the role of the environment variable names and variables that are valid for the system is fixed;
Positional parameter Variables,used primarily to pass parameters and data to the script,variable name cannot be customized,the variable action is fixed;
and define variables,is a variable already defined in base;variable name cannot be customized,variable action is also fixed;
b.user-defined variables
Defining Variables:Variable name=Variable Value(no spaces on both sides of the equals sign)
variable Invocation:Echo$ variable Name
variable Default string type
Variable Overlay:x="$x"456or x=${x}456
Set:querying all environment variables under the system
unset:Delete a variable
C.Environment variables
environment variables are global variables,user-defined variables are only valid at the current shell
The role of the environment variable name and variable that is valid for the system is fixed
Setting Environment Variables:Export variable name=variable Value or variable name=variable Value export variable name
Env: view environment variables under system
Common Environment Variables:
BASE/SHELL/HOSTNAME/hostsize/ssh_client/USER/PATH/HOME/Lang et
Recommended environment variable capitalization
PATH:System Search Command path directory,PATH="$PATH":/usr/Local/Apache
want to take effect permanently,need to write the contents into the file
PS1 Environment Variables: \u,\A,\h,\W,\W,\s,

Language Variables:
Current language Query:locale
Lang:variables that define system subject lines
Lc_all:Define a Global language variable
Cat/etc/Sysconfig/i18n system default language
D.Positional parameter variables
$n,N is a number,1-9
Vim num.SH
#!/bin/bash
NUM1=$1
num2=$2
sum=$(($num 1+$num 2))
#变量sum是num1和num2的综合
Echo$sum

Execution./Num.SH11 22


$*,this variable represents all the arguments in the command line,$*think of all the parameters as a whole.

$@,This variable also represents all the arguments in the command line,but$@each parameter is treated differently.

$#, this variable represents the number of all parameters in the command line


e.pre-defined variables
$?,return status of the last command executed。if the value of this variable is 0,prove that the last command was executed correctly;if the value of this variable is not 0,proves that the previous command was not executed correctly。
$$,process number of the current process
$!,process number of the last process running in the background

Accept Keyboard Input
Read[Options][Variable name]
-P"Prompt Information":while waiting for the read input,OUTPUT hint Information
-t number of seconds:The read command waits for the user to enter,Specify the wait time here
-n number of characters:the Read command accepts only the specified number of characters,it will execute.
-s:hide the input data,input used for confidential information

Vim Read.SH
#!/bin/bash

Read"Please input your name:"-T -Name
Echo$name

Read"Please input your pass:"-T --S Pass
EchoPass

LINUX_10------Linux Shell programming------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.