linux bash内置命令与普通命令的区别:which查不到的都是bash内置命令
[root@localhost ~]# which cd
/usr/bin/cd
[root@localhost ~]# which history
/usr/bin/which: no history in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
history是bash内置命令,能不能开启由bash说了算
set -o查看是否开启
交互式查看
[root@localhost ~]# set -o | grep history
history on
在脚本里面查看
[root@localhost ~]# echo "set -o | grep history" > a.sh
[root@localhost ~]# sh a.sh
history off
优化脚本
[root@localhost ~]# echo '#!/bin/bash' > a.sh
[root@localhost ~]# echo 'HISTFILE=~/.bash_history' >> a.sh
[root@localhost ~]# echo "set -o history" >> a.sh # 打开bash的history配置
[root@localhost ~]# echo "set -o | grep history" >> a.sh
[root@localhost ~]# sh a.sh
history on
[root@localhost ~]# echo 'history | tail' >> a.sh
[root@localhost ~]# sh a.sh
history on
59 exit
60 ifconfig
61 ss -nutpl|grep ssh
62 cat /etc/hosts | tew /tmp/hostsfile && cat /tmp/hostsfile
63 cat /etc/hosts | tee /tmp/hostsfile && cat /tmp/hostsfile
64 cat /etc/hosts | tee /tmp/hostsfile
65 cat /tmp/hostsfile
66 poweroff
67 set -o | grep history
68 history | tail
[root@localhost ~]# cat a.sh
#!/bin/bash
HISTFILE=~/.bash_history
set -o history
set -o | grep history
history | tail