Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the variable types in Linux bash Shell

Shulou Source: shulou.com Published: 2022-06-03 09:26:07 09月19日 Update

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!

Tags: Variables parameters environment processes commands programs scripts types functions systems special underscores locations contents letters parts more status knowledge control Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information MariaDB Redmi macOS