What is EOF!! in the bash script?

后端 未结 5 1628
萌比男神i
萌比男神i 2021-02-13 12:08

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 googl

相关标签:
5条回答
  • 2021-02-13 12:57

    You can use whatever string as here document terminator.

    EOF!! is just what the person writing the script decided to use.

    0 讨论(0)
  • 2021-02-13 13:01

    The bash manual lists this under "Event designators", saying:

    !!

    Refer to the previous command. This is a synonym for !-1`.

    I simply searched for "bash manual double exclamation".

    0 讨论(0)
  • 2021-02-13 13:02

    As others already wrote, this is a here-document.

    The token used for that should be chosen carefully; as the probability that the here-document contains EOF!! is lower than for EOF itself, they chose that.

    I suppose they checked it does not harm before using it; !! in a script does NOT refer to the history, but it stays as it is.

    0 讨论(0)
  • 2021-02-13 13:07

    It's probably just a weird heredoc.

    Example:

    cat << EOF!!
    blabla
    EOF!!
    

    Note: this only works in script files. The command line parser interprets !!.

    0 讨论(0)
  • 2021-02-13 13:12

    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
    
    0 讨论(0)
提交回复
热议问题