Pregunta

How can i use a variable and escape a dollar character at the same time in a shell script using cat << _EOF_?

The important thing is there is no " or ' character i'm using.

Here is my text to write:

cat <<- _EOF_ >> "$serverconfigdir/$siteaddress"
    This is a sample text! Here is my variable below!
    $usethisvariable

    This is another sample text! $escapethisstring show it how it looks bla bla.
_EOF_
¿Fue útil?

Solución

You need to escape the $ in 2nd occurrence:

cat <<- _EOF_ >> "$serverconfigdir/$siteaddress"
    This is a sample text! Here is my variable below!
    $usethisvariable

    This is another sample text! \$escapethisstring show it how it looks bla bla.
_EOF_
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top