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

Record special variables in shell scripts

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

Share

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

1. Special position variable

For the description of the relevant variables above, you can also refer to the man manual, execute the command "man bash", and then search for the keyword "Special Parameters" to see the explanation of the relevant variables.

2. Bash shell built-in variable commands

Bash Shell contains some built-in commands. These built-in commands are not visible in the directory list and are provided by Shell itself. Common internal commands are: echo, eval, exec, export, read, shift.

(1) echo-- outputs information on the screen

The common parameters are as follows:

(2) export-- converts custom local variables to global variables.

(3) shift-- offsets the position variable

If you write shift in the script, it will change the original $1, $2. The content of the corresponding variable is offset backward by default, the original $2 becomes $1, and the original $1 is gone. You can also write "shift 3" in the script, which means that the original $4 will be offset by three digits, and the original $4 will become $1 and $5 will become $2. So, what if my location variables are only two? it will be offset cyclically, assuming that now $1 corresponds to "a", $2 corresponds to b, and I wrote a line of "shift 5" in my script, then it will offset $1 and $2 cycles, and the final result $1 corresponds to b.

As for other commands that are not commonly used, if necessary, use your own Baidu method, which will not be explained here.

3. Shell variable string

You can use the following table to learn about the variable string of shell, or you can search "Parameter Expansion" after executing the "man bash" command to find an introduction.

Summary of matching deletions in the above table:

# means the shortest match is deleted from the beginning; # # means the longest match is deleted from the beginning;% means the longest match is deleted from the end;% means the longest match is deleted from the end; a "/" means to replace the first string of the match; two "/" means to replace all strings that match.

-this is the end of this article. Thank you for reading-

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