How to use an escaped file-name string saved within a bash variable in a new shell command? [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
This question already has an answer here:
Why I can't escape spaces on a bash script? [duplicate]
3 answers
How to pass directory with escaped space to variable?
3 answers
Problem:
I have an escaped string saved within a variable:
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
but whenever I try to use this file name within the following command, I get an error message saying that this path does not exist (even though it does).
/usr/bin/mysql -u root -pmypassword system < "$escapedFileName";
When i use the path and not the string it works :
/usr/bin/mysql -u root -pmypassword system < /dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql
What am I doing wrong ?
linux bash
New contributor
marked as duplicate by Goro, roaima, Isaac, Kiwy, Anthony Geoghegan Oct 2 at 10:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
2
down vote
favorite
This question already has an answer here:
Why I can't escape spaces on a bash script? [duplicate]
3 answers
How to pass directory with escaped space to variable?
3 answers
Problem:
I have an escaped string saved within a variable:
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
but whenever I try to use this file name within the following command, I get an error message saying that this path does not exist (even though it does).
/usr/bin/mysql -u root -pmypassword system < "$escapedFileName";
When i use the path and not the string it works :
/usr/bin/mysql -u root -pmypassword system < /dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql
What am I doing wrong ?
linux bash
New contributor
marked as duplicate by Goro, roaima, Isaac, Kiwy, Anthony Geoghegan Oct 2 at 10:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@don_crissti that is not duplicate, in many ways it is the opposite.
â ctrl-alt-delor
Oct 1 at 18:01
so this is not a duplicate question ?
â Lukas
Oct 1 at 19:02
1
There's always a duplicate out there but someone has to find it... Here's a better candidate (I can no longer vote to close this one): Why I can't escape spaces on a bash script?. Note that only one answer there is correct. Both braiam's and daisy's answers are wrong (as you already know now) - double quoting the variable doesn't solve this problem. Not surprisingly, one of those answers is accepted and has an insane number of upvotes...
â don_crissti
Oct 1 at 19:26
@don_crissti ^^ there you are
â roaima
Oct 1 at 20:28
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
This question already has an answer here:
Why I can't escape spaces on a bash script? [duplicate]
3 answers
How to pass directory with escaped space to variable?
3 answers
Problem:
I have an escaped string saved within a variable:
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
but whenever I try to use this file name within the following command, I get an error message saying that this path does not exist (even though it does).
/usr/bin/mysql -u root -pmypassword system < "$escapedFileName";
When i use the path and not the string it works :
/usr/bin/mysql -u root -pmypassword system < /dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql
What am I doing wrong ?
linux bash
New contributor
This question already has an answer here:
Why I can't escape spaces on a bash script? [duplicate]
3 answers
How to pass directory with escaped space to variable?
3 answers
Problem:
I have an escaped string saved within a variable:
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
but whenever I try to use this file name within the following command, I get an error message saying that this path does not exist (even though it does).
/usr/bin/mysql -u root -pmypassword system < "$escapedFileName";
When i use the path and not the string it works :
/usr/bin/mysql -u root -pmypassword system < /dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql
What am I doing wrong ?
This question already has an answer here:
Why I can't escape spaces on a bash script? [duplicate]
3 answers
How to pass directory with escaped space to variable?
3 answers
linux bash
linux bash
New contributor
New contributor
edited Oct 1 at 20:29
roaima
40.9k547111
40.9k547111
New contributor
asked Oct 1 at 17:35
Lukas
132
132
New contributor
New contributor
marked as duplicate by Goro, roaima, Isaac, Kiwy, Anthony Geoghegan Oct 2 at 10:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Goro, roaima, Isaac, Kiwy, Anthony Geoghegan Oct 2 at 10:47
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@don_crissti that is not duplicate, in many ways it is the opposite.
â ctrl-alt-delor
Oct 1 at 18:01
so this is not a duplicate question ?
â Lukas
Oct 1 at 19:02
1
There's always a duplicate out there but someone has to find it... Here's a better candidate (I can no longer vote to close this one): Why I can't escape spaces on a bash script?. Note that only one answer there is correct. Both braiam's and daisy's answers are wrong (as you already know now) - double quoting the variable doesn't solve this problem. Not surprisingly, one of those answers is accepted and has an insane number of upvotes...
â don_crissti
Oct 1 at 19:26
@don_crissti ^^ there you are
â roaima
Oct 1 at 20:28
add a comment |Â
@don_crissti that is not duplicate, in many ways it is the opposite.
â ctrl-alt-delor
Oct 1 at 18:01
so this is not a duplicate question ?
â Lukas
Oct 1 at 19:02
1
There's always a duplicate out there but someone has to find it... Here's a better candidate (I can no longer vote to close this one): Why I can't escape spaces on a bash script?. Note that only one answer there is correct. Both braiam's and daisy's answers are wrong (as you already know now) - double quoting the variable doesn't solve this problem. Not surprisingly, one of those answers is accepted and has an insane number of upvotes...
â don_crissti
Oct 1 at 19:26
@don_crissti ^^ there you are
â roaima
Oct 1 at 20:28
@don_crissti that is not duplicate, in many ways it is the opposite.
â ctrl-alt-delor
Oct 1 at 18:01
@don_crissti that is not duplicate, in many ways it is the opposite.
â ctrl-alt-delor
Oct 1 at 18:01
so this is not a duplicate question ?
â Lukas
Oct 1 at 19:02
so this is not a duplicate question ?
â Lukas
Oct 1 at 19:02
1
1
There's always a duplicate out there but someone has to find it... Here's a better candidate (I can no longer vote to close this one): Why I can't escape spaces on a bash script?. Note that only one answer there is correct. Both braiam's and daisy's answers are wrong (as you already know now) - double quoting the variable doesn't solve this problem. Not surprisingly, one of those answers is accepted and has an insane number of upvotes...
â don_crissti
Oct 1 at 19:26
There's always a duplicate out there but someone has to find it... Here's a better candidate (I can no longer vote to close this one): Why I can't escape spaces on a bash script?. Note that only one answer there is correct. Both braiam's and daisy's answers are wrong (as you already know now) - double quoting the variable doesn't solve this problem. Not surprisingly, one of those answers is accepted and has an insane number of upvotes...
â don_crissti
Oct 1 at 19:26
@don_crissti ^^ there you are
â roaima
Oct 1 at 20:28
@don_crissti ^^ there you are
â roaima
Oct 1 at 20:28
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You don't need to escape when you put the text between quotes.
Therefore remove the s
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
And you should not escape the :
, they don't need it, and it will break it.
1
@Kusalananda my bad, I was not thinking straight. I have now fixed my answer.
â ctrl-alt-delor
Oct 1 at 18:10
Not any quotes....straight quotes.
â Rui F Ribeiro
Oct 1 at 18:42
1
@RuiFRibeiro single ('
) of double ("
), back quotes are deprecated, in favour of$()
â ctrl-alt-delor
Oct 1 at 18:44
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 don't need to escape when you put the text between quotes.
Therefore remove the s
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
And you should not escape the :
, they don't need it, and it will break it.
1
@Kusalananda my bad, I was not thinking straight. I have now fixed my answer.
â ctrl-alt-delor
Oct 1 at 18:10
Not any quotes....straight quotes.
â Rui F Ribeiro
Oct 1 at 18:42
1
@RuiFRibeiro single ('
) of double ("
), back quotes are deprecated, in favour of$()
â ctrl-alt-delor
Oct 1 at 18:44
add a comment |Â
up vote
2
down vote
accepted
You don't need to escape when you put the text between quotes.
Therefore remove the s
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
And you should not escape the :
, they don't need it, and it will break it.
1
@Kusalananda my bad, I was not thinking straight. I have now fixed my answer.
â ctrl-alt-delor
Oct 1 at 18:10
Not any quotes....straight quotes.
â Rui F Ribeiro
Oct 1 at 18:42
1
@RuiFRibeiro single ('
) of double ("
), back quotes are deprecated, in favour of$()
â ctrl-alt-delor
Oct 1 at 18:44
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You don't need to escape when you put the text between quotes.
Therefore remove the s
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
And you should not escape the :
, they don't need it, and it will break it.
You don't need to escape when you put the text between quotes.
Therefore remove the s
escapedFileName='/dbDumps/Mon Oct 1 15:22:50 UTC 2018.sql'
And you should not escape the :
, they don't need it, and it will break it.
edited Oct 1 at 18:06
answered Oct 1 at 17:59
ctrl-alt-delor
9,23831948
9,23831948
1
@Kusalananda my bad, I was not thinking straight. I have now fixed my answer.
â ctrl-alt-delor
Oct 1 at 18:10
Not any quotes....straight quotes.
â Rui F Ribeiro
Oct 1 at 18:42
1
@RuiFRibeiro single ('
) of double ("
), back quotes are deprecated, in favour of$()
â ctrl-alt-delor
Oct 1 at 18:44
add a comment |Â
1
@Kusalananda my bad, I was not thinking straight. I have now fixed my answer.
â ctrl-alt-delor
Oct 1 at 18:10
Not any quotes....straight quotes.
â Rui F Ribeiro
Oct 1 at 18:42
1
@RuiFRibeiro single ('
) of double ("
), back quotes are deprecated, in favour of$()
â ctrl-alt-delor
Oct 1 at 18:44
1
1
@Kusalananda my bad, I was not thinking straight. I have now fixed my answer.
â ctrl-alt-delor
Oct 1 at 18:10
@Kusalananda my bad, I was not thinking straight. I have now fixed my answer.
â ctrl-alt-delor
Oct 1 at 18:10
Not any quotes....straight quotes.
â Rui F Ribeiro
Oct 1 at 18:42
Not any quotes....straight quotes.
â Rui F Ribeiro
Oct 1 at 18:42
1
1
@RuiFRibeiro single (
'
) of double ("
), back quotes are deprecated, in favour of $()
â ctrl-alt-delor
Oct 1 at 18:44
@RuiFRibeiro single (
'
) of double ("
), back quotes are deprecated, in favour of $()
â ctrl-alt-delor
Oct 1 at 18:44
add a comment |Â
@don_crissti that is not duplicate, in many ways it is the opposite.
â ctrl-alt-delor
Oct 1 at 18:01
so this is not a duplicate question ?
â Lukas
Oct 1 at 19:02
1
There's always a duplicate out there but someone has to find it... Here's a better candidate (I can no longer vote to close this one): Why I can't escape spaces on a bash script?. Note that only one answer there is correct. Both braiam's and daisy's answers are wrong (as you already know now) - double quoting the variable doesn't solve this problem. Not surprisingly, one of those answers is accepted and has an insane number of upvotes...
â don_crissti
Oct 1 at 19:26
@don_crissti ^^ there you are
â roaima
Oct 1 at 20:28