如何在shell脚本里开启history命令。

Posted linuxfan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在shell脚本里开启history命令。相关的知识,希望对你有一定的参考价值。

1.linux bash内置命令与普通命令的区别:which查不到的都是bash内置命令

 

2.history是bash内置命令,能不能开启由bash说了算

 

3.set -o查看是否开启

1)在交互式查看

[[email protected] ~]# set -o |grep history
history on

2)在脚本里查看

[[email protected] ~]# sh a.sh
history off

脚本内容:

##! /bin/sh
HISTFILE=~/.bash_history
set -o |grep history

 

4.set -o 命令 打开bash的history配置

脚本内容

##! /bin/sh
HISTFILE=~/.bash_history
set -o history
history

执行结果 :

技术分享图片

 








以上是关于如何在shell脚本里开启history命令。的主要内容,如果未能解决你的问题,请参考以下文章

linux 中如何执行脚本?

Shell-- 基础知识

source命令

怎么在shell 里,中断shell中某个命令,再执行下个命令

执行shell脚本三种方法的区别:(sh、exec、source)

在shell脚本里使用cd命令为啥没有效果