Linux Shell学习(3)

1. Path Name Expansion
{pattern1,pattern2,..}
注意不能有空格。
e.g.
root@localhost :~# echo file{1,2,3,5{6,7.8}}.txt
file1.txt file2.txt file3.txt file56.txt file57.8.txt


2. 设置终端输出的颜色
root@test-desktop:/home/James# echo -e "\033[32;40;5;1m ok \033[0m"
 ok


3. test command
condition: an expression that evaluates to a boolean value
test condition && true-command || false-command
test condition && true-command
test condition && false-command
(注意,如果要比较数字大小,不能用> <,因为在shell中,他们的语义是重定向!要用-gt或者-lt)
e.g.
root@localhost :~# test 1 -le 2 && echo Yes || echo No
Yes
root@localhost :~# test 1 -gt 2 && echo Yes || echo No 
No
root@localhost :~# test 5 = 5 && echo Yes || echo No
Yes
root@localhost :~# test 5 = 15 && echo Yes || echo No
No
root@localhost :~# test 5 != 5 && echo Yes || echo No
No

4. if statements
if test condition; then
 command1
 command2
 ...

fi


if [ condition ]; then
 command1
 command2
 ....
 
fi


5. conditional execution
command1 && command-success  
command1 || command-fail
command1 && command-success || command-fail

[ condition ] && true-command
[ condition ] || false-command


6. 命令行参数(command line parameters)
也叫做位置参数(positional parameters),因为我们用$1 $2等来访问他们。
$# -- 参数个数
$@ -- 等价于"$1" "$2" ... "$n"
$* -- 等价于"$1y$2y...y$n",其中y是$IFS,这暗示了如果我们改变IFS,可以改变$*的输出形式,比如IFS=","。


7. case statement
case $var-name in
 pattern1|pattern2)
  command1
  ...
  commandn
  ;;
 pattern3|pattern4)
  command1
  ...
  commandn
  ;;
 *)
  command
  ;;
esac

 

 

 

 

你可能感兴趣的:(Linux Shell学习(3))