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

Getting started with shell variables

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Temporary variable

Open a new sh, temporary variable does not exist

When the shell script runs, it looks for the system environment variable ENV first

This variable specifies the environment file (the loading order is usually / etc/profile ~. Bash_profile ~ /. Bashrc / etc/bashrc)

Realize the local effect of the variable

Edit user variable file

Order with immediate effect

Open a new sh and the variable exists

Switch between ordinary users. The variable does not exist.

Implement direct execution of scripts under / mnt

Edit user variable file

Show PATH environment variables

Make the variable take effect globally

Edit system variable file

Order with immediate effect

Switch between ordinary users. Variable exists.

.

Double quotation marks: what you see is not what you get, it will parse the variable first and then output it.

Add double quotation marks to display *

The following symbols cannot be parsed

Single quotation marks: WYSIWYG

Backslash (\): escape character / escape character, Linux if echo wants the escape character to work, use the-e option and use double quotation marks for the escape character

Back quotation mark (``): command substitution, usually used to pass the output of a command to a variable

Another way

.

The use of the $symbol

Edit a file

$1 $2 $3 is the order in which parameters are passed, and $* $@ is all $# is the number of parameters $0 is the file name

Pass parameter 1 2 3! [] (https://s1.51cto.com/images/blog/201909/03/3de2a851e6f55f838583eb550a3a1f8e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

Distinguish $* $@

Br/ >! [] (https://s1.51cto.com/images/blog/201909/03/3de2a851e6f55f838583eb550a3a1f8e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

Distinguish $* $@

Edit a file

Pass parameter 1 2 3! [] (https://s1.51cto.com/images/blog/201909/03/8c91ff9728fa49f7de85cd9ee6df8c33.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

$@ returns each parameter as a string

Br/ >! [] (https://s1.51cto.com/images/blog/201909/03/8c91ff9728fa49f7de85cd9ee6df8c33.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

$@ returns each parameter as a string

Pass parameter 1 2 3

$! The PID of the background Process where Shell was last run (the process ID number of the last process running in the background)

$? The end code (return value) of the last running command is the return value of the execution of the previous instruction (showing the exit status of the last command. 0 means there is no error, and any other value indicates an error)

The PID of $Shell itself (ProcessID, that is, the ID number of the current process in which the script is running)

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

Servers

Wechat

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

12
Report