二个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 '*'
*

 

 

 

你可能感兴趣的:(shell,String,File,null,bash,2010)