+ -
当前位置:首页 → 问答吧 → 关于history命令的问题

关于history命令的问题

时间:2011-02-01

来源:互联网

#!/bin/bash
mkdir OPS435lab2
cd OPS435lab2
mkdir -p sub1 sub2
find ./ -type d -exec touch {}/testfile \;
find /etc/passwd -exec cat {} \; > ./sub1/testfile
grep uucp ./sub1/testfile > ./sub2/testfile
sort ./sub1/testfile |cut -f 1,2  >> ./sub2/testfile
cd ..
touch lab2.final
history 10 > lab2.final



我写了这个script,要求用history命令,把最后10次的操作命令 输出到lab2.final 里。结果我运行了,lab2.final里什么也没有。什么原因呢?

如果不用script,一条一条的执行上面的命令,最后再history一下,lab2.final里是有东西的。

请高手帮忙指点一下

作者: afton   发布时间: 2011-02-01

回复 afton


     history |tail -10

作者: yinyuemi   发布时间: 2011-02-01

回复 yinyuemi


    这个我早就试过了,但lab2.final里依旧是没有东西

作者: afton   发布时间: 2011-02-01

本帖最后由 yinyuemi 于 2011-02-01 10:15 编辑

回复 afton


    you can run script like this
  1. . script.sh
复制代码
not
  1. . /script.sh
复制代码
[

作者: yinyuemi   发布时间: 2011-02-01

方法1:把bash换成其它shell
方法2:在开头加一行set -o history
  1. #!/bin/bash
  2. set -o history
  3. mkdir OPS435lab2
  4. cd OPS435lab2
  5. mkdir -p sub1 sub2
  6. find ./ -type d -exec touch {}/testfile \;
  7. find /etc/passwd -exec cat {} \; > ./sub1/testfile
  8. grep uucp ./sub1/testfile > ./sub2/testfile
  9. sort ./sub1/testfile |cut -f 1,2  >> ./sub2/testfile
  10. cd ..
  11. touch lab2.final
  12. history 10 > lab2.final
复制代码

作者: Shell_HAT   发布时间: 2011-02-01

路径问题?
  1. history 10 > ./lab2.final
复制代码

作者: 是我别封号   发布时间: 2011-02-01

回复 Shell_HAT


   我用第二种方法结果就对了,谢谢

作者: afton   发布时间: 2011-02-01

回复 是我别封号


不是。
bash默认情况下只有 interactive shell 的  history 选项打开了

作者: Shell_HAT   发布时间: 2011-02-01

热门下载

更多