Keep backslash and linebreak with EOF

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I'm creating a file with EOF like this:



cat <<EOF > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


But the result is:



RUN apt-get update -y && apt-get install -y bsdtar git locales


I want to keep the backslash and the linebreak







share|improve this question
















  • 1




    Double the backslashes; or quote-or-backslash the EOF (or any char(s) in it) to prevent all modification of the heredoc. See the bash manual section on heredocs
    – dave_thompson_085
    Oct 21 '17 at 7:24














up vote
3
down vote

favorite












I'm creating a file with EOF like this:



cat <<EOF > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


But the result is:



RUN apt-get update -y && apt-get install -y bsdtar git locales


I want to keep the backslash and the linebreak







share|improve this question
















  • 1




    Double the backslashes; or quote-or-backslash the EOF (or any char(s) in it) to prevent all modification of the heredoc. See the bash manual section on heredocs
    – dave_thompson_085
    Oct 21 '17 at 7:24












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm creating a file with EOF like this:



cat <<EOF > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


But the result is:



RUN apt-get update -y && apt-get install -y bsdtar git locales


I want to keep the backslash and the linebreak







share|improve this question












I'm creating a file with EOF like this:



cat <<EOF > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


But the result is:



RUN apt-get update -y && apt-get install -y bsdtar git locales


I want to keep the backslash and the linebreak









share|improve this question











share|improve this question




share|improve this question










asked Oct 21 '17 at 7:18









user3142695

362816




362816







  • 1




    Double the backslashes; or quote-or-backslash the EOF (or any char(s) in it) to prevent all modification of the heredoc. See the bash manual section on heredocs
    – dave_thompson_085
    Oct 21 '17 at 7:24












  • 1




    Double the backslashes; or quote-or-backslash the EOF (or any char(s) in it) to prevent all modification of the heredoc. See the bash manual section on heredocs
    – dave_thompson_085
    Oct 21 '17 at 7:24







1




1




Double the backslashes; or quote-or-backslash the EOF (or any char(s) in it) to prevent all modification of the heredoc. See the bash manual section on heredocs
– dave_thompson_085
Oct 21 '17 at 7:24




Double the backslashes; or quote-or-backslash the EOF (or any char(s) in it) to prevent all modification of the heredoc. See the bash manual section on heredocs
– dave_thompson_085
Oct 21 '17 at 7:24










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You need to quote the EOF token:



cat <<"EOF" > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


If you want to expand variables too, you need to escape the backslashes and not use any quotes.



Here's the corresponding man bash section.



 [n]<<[-]word
here-document
delimiter

No parameter and variable expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If any part of
word is quoted, the delimiter is the result of quote removal on word,
and the lines in the here-document are not expanded. If word is
unquoted, all lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion, the charac‐
ter sequence <newline> is ignored, and must be used to quote the
characters , $, and `.





share|improve this answer






















  • But what do I have to do if I need to use some variables (not shown in my example code)?
    – user3142695
    Oct 21 '17 at 7:50










  • They will get expanded as in the common shell double quoting. If this is not desired, use single quotes, eg. cat <<'EOF' > Dockerfile.
    – Tomasz
    Oct 21 '17 at 7:52











  • I think that's not the case (i.e. with double quotes around EOF, the variables will not be expanded). Are you sure? The correct answer is in the comment by @dave_thompson_085 : double the backslashes.
    – Rastapopoulos
    Oct 21 '17 at 9:25











  • @Rastapopoulos I thought so, but it looks like I was wrong.
    – Tomasz
    Oct 21 '17 at 9:28










  • @user3142695 As in the comment above, double quoting stops expansion too. So to both expand variables and keep the backslashes, you need to escape the backslashes and not use any quotes.
    – Tomasz
    Oct 21 '17 at 9:32










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399488%2fkeep-backslash-and-linebreak-with-eof%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










You need to quote the EOF token:



cat <<"EOF" > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


If you want to expand variables too, you need to escape the backslashes and not use any quotes.



Here's the corresponding man bash section.



 [n]<<[-]word
here-document
delimiter

No parameter and variable expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If any part of
word is quoted, the delimiter is the result of quote removal on word,
and the lines in the here-document are not expanded. If word is
unquoted, all lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion, the charac‐
ter sequence <newline> is ignored, and must be used to quote the
characters , $, and `.





share|improve this answer






















  • But what do I have to do if I need to use some variables (not shown in my example code)?
    – user3142695
    Oct 21 '17 at 7:50










  • They will get expanded as in the common shell double quoting. If this is not desired, use single quotes, eg. cat <<'EOF' > Dockerfile.
    – Tomasz
    Oct 21 '17 at 7:52











  • I think that's not the case (i.e. with double quotes around EOF, the variables will not be expanded). Are you sure? The correct answer is in the comment by @dave_thompson_085 : double the backslashes.
    – Rastapopoulos
    Oct 21 '17 at 9:25











  • @Rastapopoulos I thought so, but it looks like I was wrong.
    – Tomasz
    Oct 21 '17 at 9:28










  • @user3142695 As in the comment above, double quoting stops expansion too. So to both expand variables and keep the backslashes, you need to escape the backslashes and not use any quotes.
    – Tomasz
    Oct 21 '17 at 9:32














up vote
2
down vote



accepted










You need to quote the EOF token:



cat <<"EOF" > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


If you want to expand variables too, you need to escape the backslashes and not use any quotes.



Here's the corresponding man bash section.



 [n]<<[-]word
here-document
delimiter

No parameter and variable expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If any part of
word is quoted, the delimiter is the result of quote removal on word,
and the lines in the here-document are not expanded. If word is
unquoted, all lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion, the charac‐
ter sequence <newline> is ignored, and must be used to quote the
characters , $, and `.





share|improve this answer






















  • But what do I have to do if I need to use some variables (not shown in my example code)?
    – user3142695
    Oct 21 '17 at 7:50










  • They will get expanded as in the common shell double quoting. If this is not desired, use single quotes, eg. cat <<'EOF' > Dockerfile.
    – Tomasz
    Oct 21 '17 at 7:52











  • I think that's not the case (i.e. with double quotes around EOF, the variables will not be expanded). Are you sure? The correct answer is in the comment by @dave_thompson_085 : double the backslashes.
    – Rastapopoulos
    Oct 21 '17 at 9:25











  • @Rastapopoulos I thought so, but it looks like I was wrong.
    – Tomasz
    Oct 21 '17 at 9:28










  • @user3142695 As in the comment above, double quoting stops expansion too. So to both expand variables and keep the backslashes, you need to escape the backslashes and not use any quotes.
    – Tomasz
    Oct 21 '17 at 9:32












up vote
2
down vote



accepted







up vote
2
down vote



accepted






You need to quote the EOF token:



cat <<"EOF" > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


If you want to expand variables too, you need to escape the backslashes and not use any quotes.



Here's the corresponding man bash section.



 [n]<<[-]word
here-document
delimiter

No parameter and variable expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If any part of
word is quoted, the delimiter is the result of quote removal on word,
and the lines in the here-document are not expanded. If word is
unquoted, all lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion, the charac‐
ter sequence <newline> is ignored, and must be used to quote the
characters , $, and `.





share|improve this answer














You need to quote the EOF token:



cat <<"EOF" > Dockerfile
RUN apt-get update -y
&& apt-get install -y
bsdtar
git
locales
EOF


If you want to expand variables too, you need to escape the backslashes and not use any quotes.



Here's the corresponding man bash section.



 [n]<<[-]word
here-document
delimiter

No parameter and variable expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If any part of
word is quoted, the delimiter is the result of quote removal on word,
and the lines in the here-document are not expanded. If word is
unquoted, all lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion, the charac‐
ter sequence <newline> is ignored, and must be used to quote the
characters , $, and `.






share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 21 '17 at 9:37

























answered Oct 21 '17 at 7:24









Tomasz

8,06552560




8,06552560











  • But what do I have to do if I need to use some variables (not shown in my example code)?
    – user3142695
    Oct 21 '17 at 7:50










  • They will get expanded as in the common shell double quoting. If this is not desired, use single quotes, eg. cat <<'EOF' > Dockerfile.
    – Tomasz
    Oct 21 '17 at 7:52











  • I think that's not the case (i.e. with double quotes around EOF, the variables will not be expanded). Are you sure? The correct answer is in the comment by @dave_thompson_085 : double the backslashes.
    – Rastapopoulos
    Oct 21 '17 at 9:25











  • @Rastapopoulos I thought so, but it looks like I was wrong.
    – Tomasz
    Oct 21 '17 at 9:28










  • @user3142695 As in the comment above, double quoting stops expansion too. So to both expand variables and keep the backslashes, you need to escape the backslashes and not use any quotes.
    – Tomasz
    Oct 21 '17 at 9:32
















  • But what do I have to do if I need to use some variables (not shown in my example code)?
    – user3142695
    Oct 21 '17 at 7:50










  • They will get expanded as in the common shell double quoting. If this is not desired, use single quotes, eg. cat <<'EOF' > Dockerfile.
    – Tomasz
    Oct 21 '17 at 7:52











  • I think that's not the case (i.e. with double quotes around EOF, the variables will not be expanded). Are you sure? The correct answer is in the comment by @dave_thompson_085 : double the backslashes.
    – Rastapopoulos
    Oct 21 '17 at 9:25











  • @Rastapopoulos I thought so, but it looks like I was wrong.
    – Tomasz
    Oct 21 '17 at 9:28










  • @user3142695 As in the comment above, double quoting stops expansion too. So to both expand variables and keep the backslashes, you need to escape the backslashes and not use any quotes.
    – Tomasz
    Oct 21 '17 at 9:32















But what do I have to do if I need to use some variables (not shown in my example code)?
– user3142695
Oct 21 '17 at 7:50




But what do I have to do if I need to use some variables (not shown in my example code)?
– user3142695
Oct 21 '17 at 7:50












They will get expanded as in the common shell double quoting. If this is not desired, use single quotes, eg. cat <<'EOF' > Dockerfile.
– Tomasz
Oct 21 '17 at 7:52





They will get expanded as in the common shell double quoting. If this is not desired, use single quotes, eg. cat <<'EOF' > Dockerfile.
– Tomasz
Oct 21 '17 at 7:52













I think that's not the case (i.e. with double quotes around EOF, the variables will not be expanded). Are you sure? The correct answer is in the comment by @dave_thompson_085 : double the backslashes.
– Rastapopoulos
Oct 21 '17 at 9:25





I think that's not the case (i.e. with double quotes around EOF, the variables will not be expanded). Are you sure? The correct answer is in the comment by @dave_thompson_085 : double the backslashes.
– Rastapopoulos
Oct 21 '17 at 9:25













@Rastapopoulos I thought so, but it looks like I was wrong.
– Tomasz
Oct 21 '17 at 9:28




@Rastapopoulos I thought so, but it looks like I was wrong.
– Tomasz
Oct 21 '17 at 9:28












@user3142695 As in the comment above, double quoting stops expansion too. So to both expand variables and keep the backslashes, you need to escape the backslashes and not use any quotes.
– Tomasz
Oct 21 '17 at 9:32




@user3142695 As in the comment above, double quoting stops expansion too. So to both expand variables and keep the backslashes, you need to escape the backslashes and not use any quotes.
– Tomasz
Oct 21 '17 at 9:32

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399488%2fkeep-backslash-and-linebreak-with-eof%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?