Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

here document and double backslash

Tags:

bash

shell

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

like image 760
souser Avatar asked Jun 28 '12 04:06

souser


People also ask

What is use of here document?

A HereDoc is a multiline string or a file literal for sending input streams to other commands and programs. HereDocs are especially useful when redirecting multiple commands at once, which helps make Bash scripts neater and easier to understand.

How does HereDoc work?

A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor. Choose a limit string sufficiently unusual that it will not occur anywhere in the command list and confuse matters.

What is a here document and explain how its used with a good example?

In computing, a here document (here-document, here-text, heredoc, hereis, here-string or here-script) is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file.


1 Answers

Quote the beginning here document marker:

cat <<'EOF'
Print \\hello \\world
EOF
like image 143
Dennis Williamson Avatar answered Nov 07 '22 08:11

Dennis Williamson