Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is EOF!! in the bash script?

There is a command I don't understand:

custom_command << EOF!!

I want to ask what EOF!! is in the bash script. I did find EOF with google, but google will ignore the "!!" automatically, so I cannot find EOF!!.

I know the end of the file token, but I don't exactly know what it means with the "!!" in the script. Is this a mark to force something to do something like in vim's wq! ?

Plus, why and when should we use EOF!! instead of EOF?

like image 986
Marcus Thornton Avatar asked Aug 30 '13 07:08

Marcus Thornton


1 Answers

On the command line, !! would be expanded to the last command executed. Bash will print the line for you:

$ ls
a.txt  b.txt
$ cat <<EOF!!
cat <<EOFls
>

In a script, though, history expansion is disabled by default, so the exclamation marks are part of the word.

#! /bin/bash
ls
cat <<EOF!!
echo 1
EOFls
echo 2

Produces:

a.txt  b.txt
script.sh: line 7: warning: here-document at line 3 delimited by end-of-file (wanted `EOF!!')
echo 1
EOFls
echo 2

To enable history and history expansion in a script, add the following lines:

set -o history
set -H
like image 92
choroba Avatar answered Oct 07 '22 12:10

choroba