Keep backslash and linebreak with EOF
Clash 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
shell
add a comment |Â
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
shell
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
add a comment |Â
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
shell
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
shell
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
add a comment |Â
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
add a comment |Â
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 `.
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 aroundEOF
, 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
add a comment |Â
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 `.
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 aroundEOF
, 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
add a comment |Â
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 `.
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 aroundEOF
, 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
add a comment |Â
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 `.
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 `.
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 aroundEOF
, 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
add a comment |Â
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 aroundEOF
, 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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