There are several special variables in shell scripts, which sometimes play a major role. Let's repeat them tonight and make a small summary.
These special variables are:
$ @ All variables are treated as a string
$ * Each is an independent string.
$ # Reference the number of parameters passed to the script through the command line
$0 script name itself
$ Process ID of the current command
$ _ Display result of execution of the last command
$! PID Number of the latest command running in the background
$-Pilot that references the options of the current command or script
The following small script shows the differences between them:
#!/bin/bashIFS=,echo $1echo $2echo $@echo $*echo $#echo `basename {1}`echo $!echo $-
The execution result is as follows:
[root@server45 tmp]# ./a.sh a b c d e f g h aba b c d e f g ha b c d e f g h8a.sha.sh3695hB
The shell script also provides a for loop similar to the C language in the following format:
For (a = 1; A <10; A ++) do
....
....
Done
Its syntax is similar to C, and its nesting syntax is as follows:
For (a = 1; A <= 3; A ++ ))
Do
...
For (B = 1; B <= 3; B ++ ))
Do
...
Done
Done
It can process and output two command lines at the same time, increasing the flexibility and scalability of the script.
For example
#!bin/bashfor (( a=10;a>0;a-- ))do echo "hello 1" for (( b=1;b<=10;b++ )) do echo "hello 2" donedone
[root@server45 tmp]# ./b.sh hello 1hello 2hello 2hello 2hello 2hello 2hello 2hello 2hello 2hello 2hello 2hello 1