我尝试在bash脚本中使用history命令,但它没有工作。
bash文件的代码:
#!/bin/bash
# Copy history to file history
#cd /media/saleel_almajd/Study/linux/my_scripts/
echo "start Copy history to /media/saleel_almajd/Study/linux/my_scripts/history.txt"
export HISTTIMEFORMAT='%F %T ' #to make history and date apear
我试图在bash脚本中调用以下内容:
`history -a current_history`
它应该使用这个会话执行的命令创建文件。
在shell环境中工作非常好。
在bash脚本中不工作。
我看到的信息表明,您必须在bash脚本中以不同的方式调用历史,格式如下:
#!/bin/bash
HISTFILE=~/.bash_history # Set the history file.
HISTTIMEFORMAT='%F %T ' # Set the hitory time format.
set -o history # Enable the
假设我有两个bash历史文件,如下所示:
history1.txt 1.txt
1 ls
2 cd foo
...
921 history > history1.txt
history2.txt 2.
154 vim /etc/nginx/nginx.conf
155 service nginx restart
...
1153 history > history2.txt
我知道我可以轻松地编写一个bash脚本,将这两个文件合并在一起,这样生成的文件就包含了第1行到1153行,而没有重复的历史条目.类似于下面的bash脚本:
merge.