Avoid escaping of double quotes
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have some commands I want to execute in a bash script.
Now when we use single quotes the variable is taken literal and not the value.
So doing e.g. ls "$SOME_DIR"
is not the same as ls '$SOME_DIR'
How can we handle a mix of quotes and double quotes in a way that not everything is cluttered by escaping double quotes?
E.g. how to valid something like:
ssh server.com "mkdir "/foo/bar/"$final"""
How can I avoid all these escapes since the longer the commands it becomes unreadable and very easy to break?
shell ssh quoting
add a comment |Â
up vote
2
down vote
favorite
I have some commands I want to execute in a bash script.
Now when we use single quotes the variable is taken literal and not the value.
So doing e.g. ls "$SOME_DIR"
is not the same as ls '$SOME_DIR'
How can we handle a mix of quotes and double quotes in a way that not everything is cluttered by escaping double quotes?
E.g. how to valid something like:
ssh server.com "mkdir "/foo/bar/"$final"""
How can I avoid all these escapes since the longer the commands it becomes unreadable and very easy to break?
shell ssh quoting
Hi, I have updated my solution. It was much easier than I thought initially! :)
â Rastapopoulos
Oct 16 '17 at 13:25
If possible, use a script. Or make the directory tree locally andrsync
ortar c . | ssh tar x x -C /
.
â muru
Oct 16 '17 at 13:34
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have some commands I want to execute in a bash script.
Now when we use single quotes the variable is taken literal and not the value.
So doing e.g. ls "$SOME_DIR"
is not the same as ls '$SOME_DIR'
How can we handle a mix of quotes and double quotes in a way that not everything is cluttered by escaping double quotes?
E.g. how to valid something like:
ssh server.com "mkdir "/foo/bar/"$final"""
How can I avoid all these escapes since the longer the commands it becomes unreadable and very easy to break?
shell ssh quoting
I have some commands I want to execute in a bash script.
Now when we use single quotes the variable is taken literal and not the value.
So doing e.g. ls "$SOME_DIR"
is not the same as ls '$SOME_DIR'
How can we handle a mix of quotes and double quotes in a way that not everything is cluttered by escaping double quotes?
E.g. how to valid something like:
ssh server.com "mkdir "/foo/bar/"$final"""
How can I avoid all these escapes since the longer the commands it becomes unreadable and very easy to break?
shell ssh quoting
edited Oct 16 '17 at 10:54
Jeff Schaller
32.1k849109
32.1k849109
asked Oct 16 '17 at 10:24
Jim
2,771113256
2,771113256
Hi, I have updated my solution. It was much easier than I thought initially! :)
â Rastapopoulos
Oct 16 '17 at 13:25
If possible, use a script. Or make the directory tree locally andrsync
ortar c . | ssh tar x x -C /
.
â muru
Oct 16 '17 at 13:34
add a comment |Â
Hi, I have updated my solution. It was much easier than I thought initially! :)
â Rastapopoulos
Oct 16 '17 at 13:25
If possible, use a script. Or make the directory tree locally andrsync
ortar c . | ssh tar x x -C /
.
â muru
Oct 16 '17 at 13:34
Hi, I have updated my solution. It was much easier than I thought initially! :)
â Rastapopoulos
Oct 16 '17 at 13:25
Hi, I have updated my solution. It was much easier than I thought initially! :)
â Rastapopoulos
Oct 16 '17 at 13:25
If possible, use a script. Or make the directory tree locally and
rsync
or tar c . | ssh tar x x -C /
.â muru
Oct 16 '17 at 13:34
If possible, use a script. Or make the directory tree locally and
rsync
or tar c . | ssh tar x x -C /
.â muru
Oct 16 '17 at 13:34
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
3
down vote
After much playing around with heredocs
and herestrings
, it seems that the simplest solution would be this:
ssh server.com "mkdir '/foo/bar/$final'"
Yes, bash
will do variable substitution of $final
despite the single quotes, just like it would in echo "test'$final'"
.
Note: as pointed out by @muru, this will not work if $final
contains a single quote.
To be honest that does not seem much of an improvement to me. I was hoping there was a way to avoid all the clutter from quotes
â Jim
Oct 16 '17 at 10:54
Yeah that's true... You could do it using a heredoc, but I find it even less readable. I edited my answer to include that possibility.
â Rastapopoulos
Oct 16 '17 at 11:04
"...'$var'"
working fine depends on the contents of"$final"
. What if contained single quotes?
â muru
Oct 16 '17 at 13:33
Yes, you're right. That's the only case where it wouldn't work...
â Rastapopoulos
Oct 16 '17 at 13:47
The statement "bash will do variable substitution of $final despite the single quotes" sounds confusing. In fact it won't. What happens in this case, single quoted part of the command is being send to remote shell where it has no single quotes when arrived, thus $final gets expanded by remote shell. Single quotes protects the variable from local shell expanding.
â Tagwint
Oct 16 '17 at 15:38
 |Â
show 1 more comment
up vote
1
down vote
Opposite quoting, (i.e. single quotes in double quotes, and vice versa), can substitute for escapes. Without using escapes or here documents, consider how to use echo
to display this text:
He didn't look back, and said "It can't be helped."
Surrounding it with either double or single quotes won't work. Alternating opposite quotes do work:
echo "He didn't look back, and said "'"It can'"'t be helped."'"'
Output:
He didn't look back, and said "It can't be helped."
Unfortunately, the above echo
is just as difficult to read as escapes would be.
The happy medium is to use opposite quotes and escapes both as needed to reduce the visual monotony:
echo "He didn't look back, and said "It can't be helped.""
Applied to the code:
ssh server.com 'mkdir "'"/foo/bar/$final""
This should work even if $final
contains a '
.
Unrolling the quote, we have:
'mkdir "'
, which preserves a space and an opening double quote."/foo/bar/$final"
which returns contents of$final
prior to launchingssh
."
closing double quote, preserving dirname forssh
I don't understand how this works or how I would properly apply this
â Jim
Oct 19 '17 at 7:53
add a comment |Â
up vote
0
down vote
I think the real need pretty much depends on where/when you want the variables to be expanded - before sending the commands, locally or after sending, remotely. Both cases are valid.
Either way, if your command fits in one line, I'd suggest you using <<<
redirection surrounding command with either double or single quote respectively
1. Resolving variables before sending command
final="defined_locally"; ssh server.com <<<"final="defined_remotely" ;mkdir /foo/bar/"$final" "
2. Resolving variables after sending command
final="defined_locally"; ssh server.com <<<'final="defined_remotely"; mkdir /foo/bar/"$final" '
First one will create
/foo/bar/defined_locally
and the second one will create
/foo/bar/defined_remotely
directory on the remote server
As you see there's no need in escaping in both cases untill you want to mix local and remote defined vars in one command.
UPD:
<<<
strictly speaking is not a redirection, but HERE-STRING
UPD2:
Thanks to @Rastapopoulos for pointing to the
Pseudo-terminal will not be allocated because stdin is not a terminal
messages that accompanies the command execution
Although it does no harm
What is the<<<
?
â Jim
Oct 16 '17 at 11:38
I've extended my answer with the reference to the document page
â Tagwint
Oct 16 '17 at 11:47
You would still need to callsh
though, no?
â Rastapopoulos
Oct 16 '17 at 11:49
No explicit calls for sh requried, the remote command is executed by the default user's shell there.
â Tagwint
Oct 16 '17 at 11:52
Hmm, but what's your command in this case:<<< ...
? I tried in my terminal and it does produce different results.
â Rastapopoulos
Oct 16 '17 at 11:55
 |Â
show 7 more comments
up vote
0
down vote
Is this a job for the printf
builtin?
ldo@theon:~> f='He didn'''t look back, and said "It can'''t be helped."'
ldo@theon:~> echo "$f"
He didn't look back, and said "It can't be helped."
ldo@theon:~> ssh hypatia echo "$f"
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
ldo@theon:~> ssh hypatia echo $(printf %q "$f")
He didn't look back, and said "It can't be helped."
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
After much playing around with heredocs
and herestrings
, it seems that the simplest solution would be this:
ssh server.com "mkdir '/foo/bar/$final'"
Yes, bash
will do variable substitution of $final
despite the single quotes, just like it would in echo "test'$final'"
.
Note: as pointed out by @muru, this will not work if $final
contains a single quote.
To be honest that does not seem much of an improvement to me. I was hoping there was a way to avoid all the clutter from quotes
â Jim
Oct 16 '17 at 10:54
Yeah that's true... You could do it using a heredoc, but I find it even less readable. I edited my answer to include that possibility.
â Rastapopoulos
Oct 16 '17 at 11:04
"...'$var'"
working fine depends on the contents of"$final"
. What if contained single quotes?
â muru
Oct 16 '17 at 13:33
Yes, you're right. That's the only case where it wouldn't work...
â Rastapopoulos
Oct 16 '17 at 13:47
The statement "bash will do variable substitution of $final despite the single quotes" sounds confusing. In fact it won't. What happens in this case, single quoted part of the command is being send to remote shell where it has no single quotes when arrived, thus $final gets expanded by remote shell. Single quotes protects the variable from local shell expanding.
â Tagwint
Oct 16 '17 at 15:38
 |Â
show 1 more comment
up vote
3
down vote
After much playing around with heredocs
and herestrings
, it seems that the simplest solution would be this:
ssh server.com "mkdir '/foo/bar/$final'"
Yes, bash
will do variable substitution of $final
despite the single quotes, just like it would in echo "test'$final'"
.
Note: as pointed out by @muru, this will not work if $final
contains a single quote.
To be honest that does not seem much of an improvement to me. I was hoping there was a way to avoid all the clutter from quotes
â Jim
Oct 16 '17 at 10:54
Yeah that's true... You could do it using a heredoc, but I find it even less readable. I edited my answer to include that possibility.
â Rastapopoulos
Oct 16 '17 at 11:04
"...'$var'"
working fine depends on the contents of"$final"
. What if contained single quotes?
â muru
Oct 16 '17 at 13:33
Yes, you're right. That's the only case where it wouldn't work...
â Rastapopoulos
Oct 16 '17 at 13:47
The statement "bash will do variable substitution of $final despite the single quotes" sounds confusing. In fact it won't. What happens in this case, single quoted part of the command is being send to remote shell where it has no single quotes when arrived, thus $final gets expanded by remote shell. Single quotes protects the variable from local shell expanding.
â Tagwint
Oct 16 '17 at 15:38
 |Â
show 1 more comment
up vote
3
down vote
up vote
3
down vote
After much playing around with heredocs
and herestrings
, it seems that the simplest solution would be this:
ssh server.com "mkdir '/foo/bar/$final'"
Yes, bash
will do variable substitution of $final
despite the single quotes, just like it would in echo "test'$final'"
.
Note: as pointed out by @muru, this will not work if $final
contains a single quote.
After much playing around with heredocs
and herestrings
, it seems that the simplest solution would be this:
ssh server.com "mkdir '/foo/bar/$final'"
Yes, bash
will do variable substitution of $final
despite the single quotes, just like it would in echo "test'$final'"
.
Note: as pointed out by @muru, this will not work if $final
contains a single quote.
edited Jun 15 at 13:17
answered Oct 16 '17 at 10:31
Rastapopoulos
518112
518112
To be honest that does not seem much of an improvement to me. I was hoping there was a way to avoid all the clutter from quotes
â Jim
Oct 16 '17 at 10:54
Yeah that's true... You could do it using a heredoc, but I find it even less readable. I edited my answer to include that possibility.
â Rastapopoulos
Oct 16 '17 at 11:04
"...'$var'"
working fine depends on the contents of"$final"
. What if contained single quotes?
â muru
Oct 16 '17 at 13:33
Yes, you're right. That's the only case where it wouldn't work...
â Rastapopoulos
Oct 16 '17 at 13:47
The statement "bash will do variable substitution of $final despite the single quotes" sounds confusing. In fact it won't. What happens in this case, single quoted part of the command is being send to remote shell where it has no single quotes when arrived, thus $final gets expanded by remote shell. Single quotes protects the variable from local shell expanding.
â Tagwint
Oct 16 '17 at 15:38
 |Â
show 1 more comment
To be honest that does not seem much of an improvement to me. I was hoping there was a way to avoid all the clutter from quotes
â Jim
Oct 16 '17 at 10:54
Yeah that's true... You could do it using a heredoc, but I find it even less readable. I edited my answer to include that possibility.
â Rastapopoulos
Oct 16 '17 at 11:04
"...'$var'"
working fine depends on the contents of"$final"
. What if contained single quotes?
â muru
Oct 16 '17 at 13:33
Yes, you're right. That's the only case where it wouldn't work...
â Rastapopoulos
Oct 16 '17 at 13:47
The statement "bash will do variable substitution of $final despite the single quotes" sounds confusing. In fact it won't. What happens in this case, single quoted part of the command is being send to remote shell where it has no single quotes when arrived, thus $final gets expanded by remote shell. Single quotes protects the variable from local shell expanding.
â Tagwint
Oct 16 '17 at 15:38
To be honest that does not seem much of an improvement to me. I was hoping there was a way to avoid all the clutter from quotes
â Jim
Oct 16 '17 at 10:54
To be honest that does not seem much of an improvement to me. I was hoping there was a way to avoid all the clutter from quotes
â Jim
Oct 16 '17 at 10:54
Yeah that's true... You could do it using a heredoc, but I find it even less readable. I edited my answer to include that possibility.
â Rastapopoulos
Oct 16 '17 at 11:04
Yeah that's true... You could do it using a heredoc, but I find it even less readable. I edited my answer to include that possibility.
â Rastapopoulos
Oct 16 '17 at 11:04
"...'$var'"
working fine depends on the contents of "$final"
. What if contained single quotes?â muru
Oct 16 '17 at 13:33
"...'$var'"
working fine depends on the contents of "$final"
. What if contained single quotes?â muru
Oct 16 '17 at 13:33
Yes, you're right. That's the only case where it wouldn't work...
â Rastapopoulos
Oct 16 '17 at 13:47
Yes, you're right. That's the only case where it wouldn't work...
â Rastapopoulos
Oct 16 '17 at 13:47
The statement "bash will do variable substitution of $final despite the single quotes" sounds confusing. In fact it won't. What happens in this case, single quoted part of the command is being send to remote shell where it has no single quotes when arrived, thus $final gets expanded by remote shell. Single quotes protects the variable from local shell expanding.
â Tagwint
Oct 16 '17 at 15:38
The statement "bash will do variable substitution of $final despite the single quotes" sounds confusing. In fact it won't. What happens in this case, single quoted part of the command is being send to remote shell where it has no single quotes when arrived, thus $final gets expanded by remote shell. Single quotes protects the variable from local shell expanding.
â Tagwint
Oct 16 '17 at 15:38
 |Â
show 1 more comment
up vote
1
down vote
Opposite quoting, (i.e. single quotes in double quotes, and vice versa), can substitute for escapes. Without using escapes or here documents, consider how to use echo
to display this text:
He didn't look back, and said "It can't be helped."
Surrounding it with either double or single quotes won't work. Alternating opposite quotes do work:
echo "He didn't look back, and said "'"It can'"'t be helped."'"'
Output:
He didn't look back, and said "It can't be helped."
Unfortunately, the above echo
is just as difficult to read as escapes would be.
The happy medium is to use opposite quotes and escapes both as needed to reduce the visual monotony:
echo "He didn't look back, and said "It can't be helped.""
Applied to the code:
ssh server.com 'mkdir "'"/foo/bar/$final""
This should work even if $final
contains a '
.
Unrolling the quote, we have:
'mkdir "'
, which preserves a space and an opening double quote."/foo/bar/$final"
which returns contents of$final
prior to launchingssh
."
closing double quote, preserving dirname forssh
I don't understand how this works or how I would properly apply this
â Jim
Oct 19 '17 at 7:53
add a comment |Â
up vote
1
down vote
Opposite quoting, (i.e. single quotes in double quotes, and vice versa), can substitute for escapes. Without using escapes or here documents, consider how to use echo
to display this text:
He didn't look back, and said "It can't be helped."
Surrounding it with either double or single quotes won't work. Alternating opposite quotes do work:
echo "He didn't look back, and said "'"It can'"'t be helped."'"'
Output:
He didn't look back, and said "It can't be helped."
Unfortunately, the above echo
is just as difficult to read as escapes would be.
The happy medium is to use opposite quotes and escapes both as needed to reduce the visual monotony:
echo "He didn't look back, and said "It can't be helped.""
Applied to the code:
ssh server.com 'mkdir "'"/foo/bar/$final""
This should work even if $final
contains a '
.
Unrolling the quote, we have:
'mkdir "'
, which preserves a space and an opening double quote."/foo/bar/$final"
which returns contents of$final
prior to launchingssh
."
closing double quote, preserving dirname forssh
I don't understand how this works or how I would properly apply this
â Jim
Oct 19 '17 at 7:53
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Opposite quoting, (i.e. single quotes in double quotes, and vice versa), can substitute for escapes. Without using escapes or here documents, consider how to use echo
to display this text:
He didn't look back, and said "It can't be helped."
Surrounding it with either double or single quotes won't work. Alternating opposite quotes do work:
echo "He didn't look back, and said "'"It can'"'t be helped."'"'
Output:
He didn't look back, and said "It can't be helped."
Unfortunately, the above echo
is just as difficult to read as escapes would be.
The happy medium is to use opposite quotes and escapes both as needed to reduce the visual monotony:
echo "He didn't look back, and said "It can't be helped.""
Applied to the code:
ssh server.com 'mkdir "'"/foo/bar/$final""
This should work even if $final
contains a '
.
Unrolling the quote, we have:
'mkdir "'
, which preserves a space and an opening double quote."/foo/bar/$final"
which returns contents of$final
prior to launchingssh
."
closing double quote, preserving dirname forssh
Opposite quoting, (i.e. single quotes in double quotes, and vice versa), can substitute for escapes. Without using escapes or here documents, consider how to use echo
to display this text:
He didn't look back, and said "It can't be helped."
Surrounding it with either double or single quotes won't work. Alternating opposite quotes do work:
echo "He didn't look back, and said "'"It can'"'t be helped."'"'
Output:
He didn't look back, and said "It can't be helped."
Unfortunately, the above echo
is just as difficult to read as escapes would be.
The happy medium is to use opposite quotes and escapes both as needed to reduce the visual monotony:
echo "He didn't look back, and said "It can't be helped.""
Applied to the code:
ssh server.com 'mkdir "'"/foo/bar/$final""
This should work even if $final
contains a '
.
Unrolling the quote, we have:
'mkdir "'
, which preserves a space and an opening double quote."/foo/bar/$final"
which returns contents of$final
prior to launchingssh
."
closing double quote, preserving dirname forssh
edited Oct 20 '17 at 7:32
answered Oct 19 '17 at 3:51
agc
4,1501935
4,1501935
I don't understand how this works or how I would properly apply this
â Jim
Oct 19 '17 at 7:53
add a comment |Â
I don't understand how this works or how I would properly apply this
â Jim
Oct 19 '17 at 7:53
I don't understand how this works or how I would properly apply this
â Jim
Oct 19 '17 at 7:53
I don't understand how this works or how I would properly apply this
â Jim
Oct 19 '17 at 7:53
add a comment |Â
up vote
0
down vote
I think the real need pretty much depends on where/when you want the variables to be expanded - before sending the commands, locally or after sending, remotely. Both cases are valid.
Either way, if your command fits in one line, I'd suggest you using <<<
redirection surrounding command with either double or single quote respectively
1. Resolving variables before sending command
final="defined_locally"; ssh server.com <<<"final="defined_remotely" ;mkdir /foo/bar/"$final" "
2. Resolving variables after sending command
final="defined_locally"; ssh server.com <<<'final="defined_remotely"; mkdir /foo/bar/"$final" '
First one will create
/foo/bar/defined_locally
and the second one will create
/foo/bar/defined_remotely
directory on the remote server
As you see there's no need in escaping in both cases untill you want to mix local and remote defined vars in one command.
UPD:
<<<
strictly speaking is not a redirection, but HERE-STRING
UPD2:
Thanks to @Rastapopoulos for pointing to the
Pseudo-terminal will not be allocated because stdin is not a terminal
messages that accompanies the command execution
Although it does no harm
What is the<<<
?
â Jim
Oct 16 '17 at 11:38
I've extended my answer with the reference to the document page
â Tagwint
Oct 16 '17 at 11:47
You would still need to callsh
though, no?
â Rastapopoulos
Oct 16 '17 at 11:49
No explicit calls for sh requried, the remote command is executed by the default user's shell there.
â Tagwint
Oct 16 '17 at 11:52
Hmm, but what's your command in this case:<<< ...
? I tried in my terminal and it does produce different results.
â Rastapopoulos
Oct 16 '17 at 11:55
 |Â
show 7 more comments
up vote
0
down vote
I think the real need pretty much depends on where/when you want the variables to be expanded - before sending the commands, locally or after sending, remotely. Both cases are valid.
Either way, if your command fits in one line, I'd suggest you using <<<
redirection surrounding command with either double or single quote respectively
1. Resolving variables before sending command
final="defined_locally"; ssh server.com <<<"final="defined_remotely" ;mkdir /foo/bar/"$final" "
2. Resolving variables after sending command
final="defined_locally"; ssh server.com <<<'final="defined_remotely"; mkdir /foo/bar/"$final" '
First one will create
/foo/bar/defined_locally
and the second one will create
/foo/bar/defined_remotely
directory on the remote server
As you see there's no need in escaping in both cases untill you want to mix local and remote defined vars in one command.
UPD:
<<<
strictly speaking is not a redirection, but HERE-STRING
UPD2:
Thanks to @Rastapopoulos for pointing to the
Pseudo-terminal will not be allocated because stdin is not a terminal
messages that accompanies the command execution
Although it does no harm
What is the<<<
?
â Jim
Oct 16 '17 at 11:38
I've extended my answer with the reference to the document page
â Tagwint
Oct 16 '17 at 11:47
You would still need to callsh
though, no?
â Rastapopoulos
Oct 16 '17 at 11:49
No explicit calls for sh requried, the remote command is executed by the default user's shell there.
â Tagwint
Oct 16 '17 at 11:52
Hmm, but what's your command in this case:<<< ...
? I tried in my terminal and it does produce different results.
â Rastapopoulos
Oct 16 '17 at 11:55
 |Â
show 7 more comments
up vote
0
down vote
up vote
0
down vote
I think the real need pretty much depends on where/when you want the variables to be expanded - before sending the commands, locally or after sending, remotely. Both cases are valid.
Either way, if your command fits in one line, I'd suggest you using <<<
redirection surrounding command with either double or single quote respectively
1. Resolving variables before sending command
final="defined_locally"; ssh server.com <<<"final="defined_remotely" ;mkdir /foo/bar/"$final" "
2. Resolving variables after sending command
final="defined_locally"; ssh server.com <<<'final="defined_remotely"; mkdir /foo/bar/"$final" '
First one will create
/foo/bar/defined_locally
and the second one will create
/foo/bar/defined_remotely
directory on the remote server
As you see there's no need in escaping in both cases untill you want to mix local and remote defined vars in one command.
UPD:
<<<
strictly speaking is not a redirection, but HERE-STRING
UPD2:
Thanks to @Rastapopoulos for pointing to the
Pseudo-terminal will not be allocated because stdin is not a terminal
messages that accompanies the command execution
Although it does no harm
I think the real need pretty much depends on where/when you want the variables to be expanded - before sending the commands, locally or after sending, remotely. Both cases are valid.
Either way, if your command fits in one line, I'd suggest you using <<<
redirection surrounding command with either double or single quote respectively
1. Resolving variables before sending command
final="defined_locally"; ssh server.com <<<"final="defined_remotely" ;mkdir /foo/bar/"$final" "
2. Resolving variables after sending command
final="defined_locally"; ssh server.com <<<'final="defined_remotely"; mkdir /foo/bar/"$final" '
First one will create
/foo/bar/defined_locally
and the second one will create
/foo/bar/defined_remotely
directory on the remote server
As you see there's no need in escaping in both cases untill you want to mix local and remote defined vars in one command.
UPD:
<<<
strictly speaking is not a redirection, but HERE-STRING
UPD2:
Thanks to @Rastapopoulos for pointing to the
Pseudo-terminal will not be allocated because stdin is not a terminal
messages that accompanies the command execution
Although it does no harm
edited Oct 16 '17 at 13:37
answered Oct 16 '17 at 11:28
Tagwint
1,3181612
1,3181612
What is the<<<
?
â Jim
Oct 16 '17 at 11:38
I've extended my answer with the reference to the document page
â Tagwint
Oct 16 '17 at 11:47
You would still need to callsh
though, no?
â Rastapopoulos
Oct 16 '17 at 11:49
No explicit calls for sh requried, the remote command is executed by the default user's shell there.
â Tagwint
Oct 16 '17 at 11:52
Hmm, but what's your command in this case:<<< ...
? I tried in my terminal and it does produce different results.
â Rastapopoulos
Oct 16 '17 at 11:55
 |Â
show 7 more comments
What is the<<<
?
â Jim
Oct 16 '17 at 11:38
I've extended my answer with the reference to the document page
â Tagwint
Oct 16 '17 at 11:47
You would still need to callsh
though, no?
â Rastapopoulos
Oct 16 '17 at 11:49
No explicit calls for sh requried, the remote command is executed by the default user's shell there.
â Tagwint
Oct 16 '17 at 11:52
Hmm, but what's your command in this case:<<< ...
? I tried in my terminal and it does produce different results.
â Rastapopoulos
Oct 16 '17 at 11:55
What is the
<<<
?â Jim
Oct 16 '17 at 11:38
What is the
<<<
?â Jim
Oct 16 '17 at 11:38
I've extended my answer with the reference to the document page
â Tagwint
Oct 16 '17 at 11:47
I've extended my answer with the reference to the document page
â Tagwint
Oct 16 '17 at 11:47
You would still need to call
sh
though, no?â Rastapopoulos
Oct 16 '17 at 11:49
You would still need to call
sh
though, no?â Rastapopoulos
Oct 16 '17 at 11:49
No explicit calls for sh requried, the remote command is executed by the default user's shell there.
â Tagwint
Oct 16 '17 at 11:52
No explicit calls for sh requried, the remote command is executed by the default user's shell there.
â Tagwint
Oct 16 '17 at 11:52
Hmm, but what's your command in this case:
<<< ...
? I tried in my terminal and it does produce different results.â Rastapopoulos
Oct 16 '17 at 11:55
Hmm, but what's your command in this case:
<<< ...
? I tried in my terminal and it does produce different results.â Rastapopoulos
Oct 16 '17 at 11:55
 |Â
show 7 more comments
up vote
0
down vote
Is this a job for the printf
builtin?
ldo@theon:~> f='He didn'''t look back, and said "It can'''t be helped."'
ldo@theon:~> echo "$f"
He didn't look back, and said "It can't be helped."
ldo@theon:~> ssh hypatia echo "$f"
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
ldo@theon:~> ssh hypatia echo $(printf %q "$f")
He didn't look back, and said "It can't be helped."
add a comment |Â
up vote
0
down vote
Is this a job for the printf
builtin?
ldo@theon:~> f='He didn'''t look back, and said "It can'''t be helped."'
ldo@theon:~> echo "$f"
He didn't look back, and said "It can't be helped."
ldo@theon:~> ssh hypatia echo "$f"
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
ldo@theon:~> ssh hypatia echo $(printf %q "$f")
He didn't look back, and said "It can't be helped."
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Is this a job for the printf
builtin?
ldo@theon:~> f='He didn'''t look back, and said "It can'''t be helped."'
ldo@theon:~> echo "$f"
He didn't look back, and said "It can't be helped."
ldo@theon:~> ssh hypatia echo "$f"
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
ldo@theon:~> ssh hypatia echo $(printf %q "$f")
He didn't look back, and said "It can't be helped."
Is this a job for the printf
builtin?
ldo@theon:~> f='He didn'''t look back, and said "It can'''t be helped."'
ldo@theon:~> echo "$f"
He didn't look back, and said "It can't be helped."
ldo@theon:~> ssh hypatia echo "$f"
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
ldo@theon:~> ssh hypatia echo $(printf %q "$f")
He didn't look back, and said "It can't be helped."
answered Nov 5 '17 at 8:10
Lawrence D'Oliveiro
1261
1261
add a comment |Â
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%2f398374%2favoid-escaping-of-double-quotes%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
Hi, I have updated my solution. It was much easier than I thought initially! :)
â Rastapopoulos
Oct 16 '17 at 13:25
If possible, use a script. Or make the directory tree locally and
rsync
ortar c . | ssh tar x x -C /
.â muru
Oct 16 '17 at 13:34