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 is the specific function of shell script symbols in Linux system

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly analyzes the specific role of shell script symbols in Linux system, which is related to knowledge points, detailed and easy to understand, reasonable operation details, and has certain reference value. If you are interested, you may wish to follow Xiao Bian to have a look. Let's follow Xiao Bian to learn more about "what is the specific role of shell script symbols in Linux system".

Shell scripts in Linux have many symbols, each symbol has a special role, the following is the specific role of each symbol in shell scripts in Linux system.

#! The first sentence in the footstep indicates the program used to execute the script Example: #!/ bin/bash #comment, used to help information or ignore temporarily not executed statements Example: # echo "hello" # this is a comment $Variable replacement symbol example: a=123;echo $a ${} Variable regular expression, avoid variable name early truncation Example: ${13} $num Position parameter example: $0,$1,…,${10} $? The status of the last command, generally 0 means correct, other means wrong Example: if [ $?- ne 0 ]; then echo "encounter error" fi $! Example ID of background command executed by last command: pid=$! $$ID of the process running the script Example: pid=$$ $* Parameters passed to the steps, equivalent to "$1$2 …" Example: echo "Theparameters are $*" $@ Same as $*, equivalent to "$1""$2"" …Example: a=$@ $#Number of parameters passed to the script, excluding $0 Parameter Example: echo "theparameter number is $#" $-Holds the setting information of the current shell. If there is an i in the result, it is indicated as an interactive shell example: echo $- ; Separator for writing multiple instructions on the same line Example: a=123;echo $a ;; Special language case option, similar to break in C language switch statement Example: case${tao} in a)echo "a" ;; b)echo "b" ;; esac . one for the current directory, two for the next directory Example: cd.. , similar to the comma expression example in C: let "t1=((a=5+3,b=7-1,c=15/3))";echo $t1 ! Example of logical operation "NOT": if [ "$? "!= "0" ]; then echo "Execute error" exit 1 fi : In bash, this is a built-in command,"Do nothing," but returns a status value of 0 Example:; echo$?; :> f.out is equivalent to cat/dev/null > f.out ? Wildcard, matches any character, but does not include null Example: ls f? n''treats its contents as strings, neither $nor wildcards expand or escape Example: a=1; echo '$a' results in $a "" treats its contents as strings, but $can expand, wildcards cannot Example: b="string";echo "$b" results in string `` backquotes (to the left of keyboard number 1), where the string is executed as a command Example: a=`date`;echo "$a" () Instruction group, enclosing a string of instructions, when executed shell generates subshell to execute them Example: (a=1;echo$a) (()) Built-in function of bash, used for arithmetic operations Example: a=10;echo$a;((a++)); echo $a [] Same as test, used for judging whether an expression is true or false Example: if [ 1-eq 2];then echo 'kill me' fi [[]] bash Enhanced version of [], which allows the use of|| and &&, and can use regular expressions Example: read ver if [[ $ver > 5 &&$ver regular expression, matching the beginning and ending of a word Example: find '\' file + addition, indicating that the character is repeated 1~n times in a regular expression Example: grep '10\+9' file -subtraction, standard input, indicating the previous working directory in the cd command Example: expr 1 -2 + 3; tar -zxfv -; cd-* multiplication, wildcard, representing any character; a character repeated 0~n times Example: let "var=2*3"; ls zha*t; grep 'a1[0-9]*'** Power operation Example: let "var=2**8" /Division; Directory separator Example: expr 10/2;cd /home/zc % remainder Example: expr 10%2 = assignment; String comparison, different in [] and [[]](see ==) Example: a='we';if [ $a =='wee']; then exit0 fi == String comparison, same as single equal sign Example: a=' we 'if[[ $a == w* ]]; then echo"ok" fi != String comparison, not equal Example: if [ "$a"!= "$b" ]; then... test Output redirection, file overwrite exists, does not exist New example: ls> out2>&1 >> Output redirection, file append exists, does not exist Create example: ls>>out & Background execution worker example: tar zcvfdata.tar.gz data >/dev/null && logical AND, short circuit operator example: cp1.txt2.txt && rm 1.txt && echo 'success'| Pipeline operator example: cat file| grep ‘fan’ ||Logical OR, Short Circuit Operator Example: rm1.txt|| echo 'fail'~ root directory example: cd ~ ^regular expression matching line beginning example: grep '^home' file \escape character, continuation symbol example: echo "\$A=$A\ This is the first line"; about "Linux system shell script symbol specific role is what" introduced to this, more related content can search previous articles, hope to help you answer questions, please support the website!

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