How to use an escaped file-name string saved within a bash variable in a new shell command? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash 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 ?










share|improve this question









New contributor




Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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















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 ?










share|improve this question









New contributor




Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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













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 ?










share|improve this question









New contributor




Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question









New contributor




Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Oct 1 at 20:29









roaima

40.9k547111




40.9k547111






New contributor




Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Oct 1 at 17:35









Lukas

132




132




New contributor




Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Lukas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




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

















  • @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











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.






share|improve this answer


















  • 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 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.






share|improve this answer


















  • 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















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.






share|improve this answer


















  • 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













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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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













  • 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



Popular posts from this blog

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

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay