こんにちは。
single quote を含む here-document の変数代入(下記例内のdon't
)が macOS の /bin/bash ではエラーとなることに気がつきました。
apostrophe にすべきと思いました。もしくは一旦変数に格納する回避法しか思いつきませんでした(SINGLEQUOTE="'"
)。
$ /opt/homebrew/bin/bash ./dont.sh
don't
$
$ /bin/bash ./dont.sh
./dont.sh: line 5: unexpected EOF while looking for matching `"'
./dont.sh: line 5: syntax error: unexpected end of file
$
$ cat dont.sh
#!/bin/sh
echo "$(cat << EOF
don't
EOF
)"
$
$ echo "$(cat << EOF
> don't
> EOF
> )"
>
> bash: unexpected EOF while looking for matching `''
bash: syntax error: unexpected end of file
$
$ uname -mopr
Darwin 24.3.0 arm64 arm
$ /bin/bash --version
/bin/bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin24)
Copyright (C) 2007 Free Software Foundation, Inc.