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.txtshell


2. 設置終端輸出的顏色
root@test-desktop:/home/James# echo -e "\033[32;40;5;1m ok \033[0m"
 ok express


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
Nolua

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

fi命令行


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


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

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


6. 命令行參數(command line parameters)
也叫作位置參數(positional parameters),由於咱們用$1 $2等來訪問他們。
$# -- 參數個數
$@ -- 等價於"$1" "$2" ... "$n"
$* -- 等價於"$1y$2y...y$n",其中y是$IFS,這暗示了若是咱們改變IFS,能夠改變$*的輸出形式,好比IFS=","。test


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

相關文章
相關標籤/搜索