Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Last active August 2, 2018 05:03
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hnakamur/9427958 to your computer and use it in GitHub Desktop.
bashのヒアドキュメントでエスケープしたくない場合はEOFを'EOF'にします。
$ cat ./heredoc_escape.sh
#!/bin/bash
cat <<EOF
FOO=$6$
EOF
$ ./heredoc_escape.sh
FOO=$
$ vim ./heredoc_escape.sh
$ cat ./heredoc_escape.sh
#!/bin/bash
cat <<'EOF'
FOO=$6$
EOF
$ ./heredoc_escape.sh
FOO=$6$
$ vim ./heredoc_escape.sh
$ cat ./heredoc_escape.sh
#!/bin/bash
cat <<EOF
FOO=\$6$
EOF
$ ./heredoc_escape.sh
FOO=$6$
@hnakamur
Copy link
Author

hnakamur commented Mar 8, 2014

20行目以降のように'EOF'ではなくEOFにしておいて中身をエスケープする手もあります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment