help-bash
[Top][All Lists]
Advanced

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

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


From: Peng Yu
Subject: [Help-bash] How to use !! in a script?
Date: Sat, 9 Apr 2016 18:12:20 -0500

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



reply via email to

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