Hi,
The manual says "This feature is enabled by default for interactive
shells, and can be disabled using the +H option to the set builtin
command (see SHELL BUILTIN COMMANDS below). Non-interactive shells do
not perform history expansion by default."
I am trying to use !! to refer to the previous command by enabling
histexpand. But the following example does not work. Does anybody know
what is the correct way to use !! in a script? Thanks.
~$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
tmpfile1=$(mktemp)
tmpfile2=$(mktemp)
set -o > "$tmpfile1"
set -H
set -o > "$tmpfile2"
diff "$tmpfile1" "$tmpfile2"
!!
~$ ./main.sh
8c8
< histexpand off
---
> histexpand on
./main.sh: line 10: !!: command not found
--
Regards,
Peng