문제

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