Shell script variables

Source: Internet
Author: User
Tags locale

Shell script variable What is a variable

Replace another complex or volatile data with a simple "word"

Display and setting of variables: The display of Echo,unset variables

Echo ${path}

Setting rules for variables

equal sign Connection variable = variable content

The equal sign cannot be directly connected to the whitespace

Variable names can only be English or numeric, numbers cannot be used as the first character

Variable contents have spaces that need to be enclosed in double or single quotation marks.

Single quotation marks: special characters represent only characters

Double quotation marks: special characters can maintain the original characteristics, such as $

Escape character to turn special symbols into normal characters

$ (command) and ' command ' both indicate that the command is executed first

Variable content Append

Path=${path}:/home/bin

To set a variable to an environment variable

Export PATH Note: When you do not follow the variable name in export, all environment variables are displayed

The cancellation of a variable

unset PATH

Function of environment Variables env

View all environment variables in the current shell environment

Export

View all environment variables in the current shell environment,

To turn a custom variable into an environment variable

Set

View all variables (including environment variables and custom variables)

Some useful variables ps1= ' [\[email protected]\h \w] '

Set the command prompt, which is set [[email protected] ~]#

\d: The date format of "Day of the Week" can be displayed, for example: "Mon Feb 2"

\h: Full host name. For example, Brother Bird's practice machine is "Www.vbird.tsai"

\h: Takes only the name of the hostname before the first decimal point, such as the bird's host is omitted after "www"

\ t: Show time as "HH:MM:SS" in 24-hour format

\ t: Show time as "HH:MM:SS" in 12-hour format

\a: Show time as "hh:mm" in 24-hour format

\@: Display time, "AM/PM" style for 12-hour format

\u: The current user's account name, such as "root";

\v:bash version information, such as Bird's Test motherboard is 3.2.25 (1), only "3.2" display

\w: The full working directory name, the directory name that is written by the root directory. But the main directory will be replaced by ~;

\w: Use the basename function to get the working directory name, so only the last directory name is listed.

\#: The first few instructions issued.

\$: Prompt character, if root, the prompt character is #, otherwise it is $ ~

?

Get the callback code for the previous command

Language variables that affect the display result: locale

locale-a

See how many languages Linux supports

Local

View the variables that are used to set the language family

/etc/sysconfig/i18n

Current default language

Variable keyboard read, array and declaration: Read,array,declare variable Keyboard read: Read

Read [-PT] Variable

P followed by prompt

Number of seconds to wait after T

Variable declaration: Declare

Declare [-| +][AIXR] variable

-A sets an array variable

-I sets an integer variable

-X turns the subsequent variable into an environment variable

-R Sets the variable to the readonly type, changes the contents of the item that cannot be changed, and cannot be reset

-p lists the types of variables

The + plus sign means that the type of the variable is canceled

Array type variable: array

Setup mode

Var[index]=content

Setting up instances

var[1]= "Small min"

var[2]= "Big min"

var[3]= "Nice min"

Working with instances

echo "${var[1]},${var[2],${var[3]}"

Deletion and substitution of variable contents

Testing and substitution of variables

-, + set var=expr according to STR conditions

= Set var=expr according to STR and set str=expr

? Set var=expr according to STR, abnormal output error prompt

  

Shell script 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.