Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the variable types in Linux bash Shell

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "what types of variables are there in Linux bash Shell". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Bash variable type:

Local variable

Local variable

Environment variable

Location variable

Special variables (built-in)

Second, local variables:

Varname=value: the scope is for the entire bash process to use

Variable naming convention:

1. Can only contain letters, numbers and underscores, and start with letters and underscores

two。 It is best not to have the same name as the existing environment variables of the system.

3. See the name and know the meaning

3. Local variables:

Local varname=value: scope is the current code snippet

IV. Environmental variables:

The scope is the current shell process and its child processes, and its parent process cannot be affected

Export varname=value "export", if the variable has been defined, you can just use the variable name export varname, that is

1. Export varname=value

2. Varname=value

Export varname

The script starts a child shell environment variable when it executes the command:

The script that the system executes automatically (not started on the command line) requires self-definition of the required environment variables.

Fifth, location variables:

$1, 2, 3,.

Cat first.sh test.txt hello

$1: first.sh

$2: test.txt

$3: hello

Shift: kick out the parameter

Shift n: kick out n parameters and one parameter by default

6. Special variables:

$?: the return value of the last command execution status:

Program execution may have two return values:

1. Program execution result

two。 Does the program status return (0-255)

0 means to execute correctly

1-255 execution error (1pm 2127 system reservation)

$#: gets the total number of parameters in the current shell command line

$*: get all the parameters of the current shell "$1 $2 $3 …, controlled by IFS

$@: all parameters of this program "$1"$2"$3"…", not controlled by IFS

$0 gets the file name of the currently executed shell script

$n gets the nth parameter value of the currently executed shell script, natively 1.. 9

$get the process number (PID) of the current shell

$! The PID that executed the previous instruction

This is the end of the content of "what are the variable types in Linux bash Shell". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report