1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

single quote を含む here-document の変数代入がエラーとなる(macOS の /bin/bash)

Last updated at Posted at 2025-02-27

こんにちは。
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.
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?