help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to use !! in a script?


From: Arkadiusz Drabczyk
Subject: Re: [Help-bash] How to use !! in a script?
Date: Sun, 10 Apr 2016 20:58:33 +0000 (UTC)
User-agent: slrn/1.0.1 (Linux)

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>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]