什么是EOF !! 在bash脚本中?

Mar*_*ton 12 unix linux bash shell

有一个我不明白的命令:

custom_command << EOF!!
Run Code Online (Sandbox Code Playgroud)

我想问一下EOF !! 在bash脚本中.我确实找到了谷歌的EOF,但谷歌将忽略"!!" 自动,所以我找不到EOF !!

我知道文件令牌的结束,但我不知道"!!"的意思 在脚本中.这是一个标记强迫某事做像vim的wq!?

另外,我们为什么以及何时应该使用EOF !! 而不是EOF?

cho*_*oba 15

在命令行上,!!将扩展为最后执行的命令.Bash将为您打印该行:

$ ls
a.txt  b.txt
$ cat <<EOF!!
cat <<EOFls
>
Run Code Online (Sandbox Code Playgroud)

但是,在脚本中,默认情况下会禁用历史记录扩展,因此感叹号是该单词的一部分.

#! /bin/bash
ls
cat <<EOF!!
echo 1
EOFls
echo 2
Run Code Online (Sandbox Code Playgroud)

生产:

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
Run Code Online (Sandbox Code Playgroud)

要在脚本中启用历史记录和历史记录扩展,请添加以下行:

set -o history
set -H
Run Code Online (Sandbox Code Playgroud)