当前位置: 首页 > 文档资料 > Shell 中文文档 >

Appendix J. History Commands

优质
小牛编辑
116浏览
2023-12-01

The Bash shell provides command-line tools for editing andmanipulating a user's command history. Thisis primarily a convenience, a means of saving keystrokes.

Bash history commands:

  1. history
  2. fc
bash$ 

history

   1  mount /mnt/cdrom
   2  cd /mnt/cdrom
   3  ls
   ...  

Internal variables associated with Bash history commands:

  1. $HISTCMD
  2. $HISTCONTROL
  3. $HISTIGNORE
  4. $HISTFILE
  5. $HISTFILESIZE
  6. $HISTSIZE
  7. $HISTTIMEFORMAT (Bash, ver. 3.0 or later)
  8. !!
  9. !$
  10. !#
  11. !N
  12. !-N
  13. !STRING
  14. !?STRING?
  15. ^STRING^string^

Unfortunately, the Bash history tools find no use in scripting.

   1 #!/bin/bash
   2 # history.sh
   3 # Attempt to use 'history' command in a script.
   4
   5 history
   6
   7 # Script produces no output.
   8 # History commands do not work within a script.
bash$ 
./history.sh
(no output)

 

The Advancing in theBash Shellsite gives a good introduction to the use ofhistory commands in Bash.