二个shell变量小记, HISTTIMEFORMAT ,和shopt:变量nullglob

考虑下这个二个问题:

1:“echo *在一个空目录下执行的结果如何?”
2:history输出能否带着命令执行时间?

以前在看文档(主要是man和info)时,遇到工具的变量,总是跳过去不读,将这部分当做字典,需要时再查。

事实上经典的变量,迟早是要碰到的。比如今天在群里就碰到了下边几个变量:

 

1:history里的HISTTIMEFORMAT
      在man bash的变量部分里有介绍到这个变量(以HIS开头的基本上都是history的变量)
       HISTTIMEFORMAT
              If this variable is set and not null, its value is used as a format string for strftime(3) to print  the
              time  stamp  associated  with  each history entry displayed by the history builtin.  If this variable is
              set, time stamps are written to the history file so they may be preserved across shell sessions.

 

       该变量定义了history输出之前是否带上时间,而具体的时候,与strftime函数的定义是一至的,

      使用实例:

       [root@localhost awk]# set -x  
+ set -x
[root@localhost awk]# HISTTIMEFORMAT="%F %T"
+ HISTTIMEFORMAT='%F %T'
[root@localhost awk]# history 3
+ history 3
 1102  2010-06-16 17:48:50set -x
 1103  2010-06-16 17:48:52HISTTIMEFORMAT="%F %T"
 1104  2010-06-16 17:48:54history 3

 

 

 

2:shopt下的一些变量,比如:nullglob

考虑下这个问题:“echo *在一个空目录下执行的结果如何?”

 

事实上,shell解析echo *这个命令时,会进行通配扩展(pattern expansion)

If no matching file names are found, and the shell option
       nullglob is disabled, the word is left unchanged.  If the nullglob option is set, and no matches are found, the
       word  is  removed. 

涉及到了shell一个shopt变量:

nullglob
                      If set, bash allows patterns which match no files (see Pathname Expansion above) to expand to  a
                      null string, rather than themselves.

定义对于通配符匹配时,若匹配不到时,是为空,还是本身的字符定义

 

 

 

[root@localhost start]# shopt -s nullglob   
+ shopt -s nullglob
[root@localhost start]# echo *
+ echo

[root@localhost start]# shopt -u nullglob
+ shopt -u nullglob
[root@localhost start]# echo *
+ echo '*'
*

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值