souser
souser

Reputation: 6110

here document and double backslash

If I use a here document in a shell script that contains multiple backslashes '\', the shell translates it into a single backslash. Can I work around this without changing the text ?

$ cat <<EOF  
> Print \\hello \\world  
> EOF  
Print \hello \world

Upvotes: 7

Views: 2092

Answers (2)

Phillip Nordwall
Phillip Nordwall

Reputation: 465

As an alternative to what Dennis mentions The command sed can also take care of this.

sed 's/\\/\\\\/g' <<EOF
Print \\hello \\world
EOF

Upvotes: 0

Dennis Williamson
Dennis Williamson

Reputation: 359955

Quote the beginning here document marker:

cat <<'EOF'
Print \\hello \\world
EOF

Upvotes: 15

Related Questions