shell高級技巧:用set命令設置bash的選項

下面爲set主要選項的列表及其表述:
選項名 開關縮寫 描述
allexport -a 打開此開關,所有變量都自動輸出給子Shell。
noclobber -C 防止重定向時文件被覆蓋。
noglob -d 在路徑和文件名中,關閉通配符。
    #打開該選項
    [root@xieqichao ~]# set -o allexport   #等同於set -a
    #關閉該選項
    [root@xieqichao ~]# set +o allexport  #等同於set +a
    #列出當前所有選項的當前值。
    [root@xieqichao ~]# set -o
    allexport         off
    braceexpand   on
    emacs             on
    errexit            off
    errtrace          off
    functrace        off
    hashall            on
    histexpand      on
    ... ...
    [root@xieqichao ~]# set -o noclobber     #打開noclobber選項,防止在重定向時原有文件被覆蓋。
    [root@xieqichao ~]# date > outfile         #通過date命令先生成一個文件outfile。
    [root@xieqichao ~]# ls > outfile             #將ls命令的輸出重定向到該文件outfile,shell將提示不能覆蓋已經存在的文件。
    -bash: outfile: cannot overwrite existing file
    [root@xieqichao ~]# set +o noclobber    #關閉noclobber選項。
    [root@xieqichao ~]# ls > outfile             #重新將ls的輸出重定向到outfile,成功。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章