TLDR:
Use 'EOF'
$ cat <<'EOF'
> $USER
> $(pwd)
> `pwd`
> EOF
$USER
$(pwd)
`pwd`
Sometimes when we want to create a multi-line text and redirect it to the output we will use cat EOF
like this
cat <<EOF > /tmp/out
line1
line2
EOF
and the result will be like this:
line1
line2
but if we're gonna pass variables to the line, we're gonna see it works like this:
cat <<EOF > /tmp/out
$USER
$(pwd)
`pwd`
EOF
output:
clavinjune
/tmp
/tmp
if we want to keep the variables as it is we can use 'EOF'
instead.
cat <<'EOF' > /tmp/out
$USER
$(pwd)
`pwd`
EOF
output:
$USER
$(pwd)
`pwd`
Top comments (0)