bashshellcatheredoc

How to preserve newlines with cat command


I have this:

echo `cat << 'EOF'
    select c1, c2 from foo
    where c1='something'
EOF`

it logs this to stdout:

select c1, c2 from foo where c1='something'

but I am looking to preserve newlines somehow, so it outputs:

select c1, c2 from foo  
where c1='something'

How can I do that?


Solution

  • Use double quotes with echo to preserve the original format of the string.

    echo "`cat << 'EOF'
        select c1, c2 from foo
        where c1='something'
    EOF`"