关于history命令的问题
时间:2011-02-01
来源:互联网
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
history |tail -10
作者: yinyuemi 发布时间: 2011-02-01
这个我早就试过了,但lab2.final里依旧是没有东西
作者: afton 发布时间: 2011-02-01
回复 afton
you can run script like this
- . script.sh
- . /script.sh
作者: yinyuemi 发布时间: 2011-02-01
方法2:在开头加一行set -o history
- #!/bin/bash
- set -o history
- 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
作者: Shell_HAT 发布时间: 2011-02-01
- history 10 > ./lab2.final
作者: 是我别封号 发布时间: 2011-02-01
我用第二种方法结果就对了,谢谢
作者: afton 发布时间: 2011-02-01
不是。
bash默认情况下只有 interactive shell 的 history 选项打开了
作者: Shell_HAT 发布时间: 2011-02-01
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28