Home > OS >  Shell script command
Shell script command

Time:10-10

Linux variable, the basename, $#, $@, $0, $1, $2, $* and $$, $? [- eq] [- ne] [- gt] [- lt] [its] [le] the meaning of

$# is the number of parameters to the script
$0 is the name of the script itself
$1 is passed to the first parameter to the shell script
$2 is passed to the shell script of the second parameter
$@ is a list of all parameters to the script
$* is a single string display all parameters, delivered to the script and position variables, parameters can be more than 9
$$is script to run the current process ID of the
$? Is the last command displays the exit status, 0 means no error, the other says there is an error

The basename is what remains after one has to remove directory name
Example: shell> Temp=/home/temp/1. The test
Shell> The base=` the basename $temp `
Shell> Echo $base
Results as follows: 1. The test
Dirname are take directory
Example: shell> Temp=/home/temp/1. The test
Shell> Dir=` dirname $temp `
Shell> Echo $dir
The result is:/home/temp

Another kind of implementation method:
${var# # */} is the last/variable var and to the left of the content to remove
${var/* %} is the last/variable var and the content of the right to remove


Difference: @ *

Similarities: all are reference

Difference: only in double quotes, we assume that the scripting runtime wrote three parameters (3) are stored in 12 "*" is equivalent to "12 3" passed a parameter (); The "@" equivalent to "1" "2" "$3" passed three parameters ()

- eq//equal to

Ne//is not equal to

- gt//than (greater)

- lt//less than (less)

- ge//greater than or equal to

Le//less than or equal to

Logical relationship of command:

In Linux command execution status: 0 is true, the other is false

Logic and: & amp; & -a
When the first condition is false, the second condition don't have to judge, have been the end result;
First condition to true, the second condition must judge;
Logic or: | |
Logic is not:!

Example 1:

1 # # dels. Sh 2 echo "number: $# 3" echo "scname: $0" four echo "first: $1, 5" echo "second: $2" 6 echo "argume: $@ 7" echo "show the parm list: $* 8" echo "show the process id: $$9" echo "show precomm stat: $?"

The results as follows:

  • Related