On 2016-04-09, Peng Yu <address@hidden> wrote:
> 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"
> !!
You forgot `set -o history'. It should be:
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
tmpfile1=$(mktemp)
tmpfile2=$(mktemp)
set -o > "$tmpfile1"
set -H
set -o history
set -o > "$tmpfile2"
diff "$tmpfile1" "$tmpfile2"
!!
--
Arkadiusz Drabczyk <address@hidden>