set命令參數:
-a 標示已修改的變量,以供輸出至環境變量。 -b 使被中止的後臺程序立刻回報執行狀態。 -C 轉向所產生的文件無法覆蓋已存在的文件。 -d Shell預設會用雜湊表記憶使用過的指令,以加速指令的執行。使用-d參數可取消。 -e 若指令傳回值不等於0,則立即退出shell。 -f 取消使用通配符。 -h 自動記錄函數的所在位置。 -H Shell 可利用"!"加<指令編號>的方式來執行history中記錄的指令。 -k 指令所給的參數都會被視爲此指令的環境變量。 -l 記錄for循環的變量名稱。 -m 使用監視模式。 -n 只讀取指令,而不實際執行。 -p 啓動優先順序模式。 -P 啓動-P參數後,執行指令時,會以實際的文件或目錄來取代符號連接。 -t 執行完隨後的指令,即退出shell。 -u 當執行時使用到未定義過的變量,則顯示錯誤信息。 -v 顯示shell所讀取的輸入值。 -x 執行指令後,會先顯示該指令及所下的參數。 +<參數> 取消某個set曾啓動的參數。例子set -x:在腳本文件中加入了命令set –x ,那麼在set命令之後執行的每一條命令以及加載命令行中的任何參數都會顯示出來,每一行都會加上加號(+),提示它是跟蹤輸出的標識,在子shell中執行的shell跟蹤命令會加2個叫號(++)。
1: [root@centos6 shell]# cat set-x.sh
2: #!/bin/bash
3: #set -x
4: echo -n "Can you write device drivers?"5: read answer
6: answer=$(echo $answer | tr [a-z] [A-Z])
7: if [ $answer = Y ]8: then
9: echo "Wow,you must be very skilled"10: else11: echo "Neither can I,I am just an example shell script"12: fi
13: [root@centos6 shell]# sh set-x.sh
14: Can you write device drivers?y
15: Wow,you must be very skilled
16: [root@centos6 shell]# sh set-x.sh
17: Can you write device drivers?n
18: Neither can I,I am just an example shell script
19: [root@centos6 shell]#
1: [root@centos6 shell]# sh set-x.sh
2: + echo -n 'Can you write device drivers?'
3: Can you write device drivers?+ read answer
4: y
5: ++ echo y
6: ++ tr '[a-z]' '[A-Z]'
7: + answer=Y
8: + '[' Y = Y ']'
9: + echo 'Wow,you must be very skilled'
10: Wow,you must be very skilled
11: [root@centos6 shell]# sh set-x.sh
12: + echo -n 'Can you write device drivers?'
13: Can you write device drivers?+ read answer
14: n
15: ++ echo n
16: ++ tr '[a-z]' '[A-Z]'
17: + answer=N
18: + '[' N = Y ']'
19: + echo 'Neither can I,I am just an example shell script'
20: Neither can I,I am just an example shell script
21: [root@centos6 shell]#
參考:http://world77.blog.51cto.com/414605/859129
http://www.runoob.com/linux/linux-comm-set.html