سؤال

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_
هل كانت مفيدة؟

المحلول

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_
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top