Lundi 14 octobre 2024 à 14:24

#JaiDécouvert en Bash que si EOF est entre guillements, c'est-à-dire 'EOF' alors les variables $ ne seront pas substitué.

Exemple, le script suivant :

cat <<'EOF' > /test.sh
echo "Hello, $USER"
EOF

est l'équivalent de :

cat <<EOF > /test.sh
echo "Hello, \$USER"
EOF

Documentation à ce sujet dans la seciton "Here Documents" du manuel de Bash :

No parameter and variable expansion, command substitution, arithmetic expansion, or filename expansion is performed on word. If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded.
If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence \newline is ignored, and ‘\’ must be used to quote the characters ‘\’, ‘$’, and ‘`’.

Quitter le mode Zen