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,成功。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值