bash how to script if I expect both spaces and symbols like `~` in path variables?Why doesn't the tilde (~)...

What are the branches of statistics?

Disordered Cryptic Orders

How does Firefox know my ISP login page?

What is "demographic engineering" and how does it differ from ethnic cleansing?

Who is Sifter, and what is "the so-called Sifter flare"?

Anatomically Correct Baku

Can you upgrade armour from breastplate to halfplate?

How should the 23rd judge vote?

In "Avatar: The Last Airbender" can a metalbender bloodbend if there is metal in our blood?

'Pound' meaning in this context

What is the design rationale for having armor and magic penetration mechanics?

How to protect my Wi-Fi password from being displayed by Android phones when sharing it with QR code?

Do businesses save their customers' credit card information until the payment is finalized?

Is there a historical explanation as to why the USA people are so litigious compared to France?

Front hydraulic disk brake is too powerful on MTB — solutions?

When did 5 foot squares become standard in D&D?

How can I prove mathematically the reflection matrix has only the eigenvalues 1 or -1?

Slaad Chaos Phage: Weak Combat Ability?

Why is my for loop stuck on the second option?

In the comics, have any of the Robins called their costume "target attraction" for villains?

Showing a limit approaches e: base of natural log

Extra battery in the bay of an HDD

What does すきすき mean here?

How many records can an Apex Batch process



bash how to script if I expect both spaces and symbols like `~` in path variables?


Why doesn't the tilde (~) expand inside double quotes?Auto-expansion problem with array elements containing an '*' (asterisk)`expect`-like behaviour in bash scriptKVM reports strange CPU usage peaks (bash infinite recursion)Spaces for variables in bash scriptWhy does a 'sudo -i' login shell break a here-doc command string argument?How can I replace all spaces outside double quotes by n?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}








0

















Why ~ does not expand in $ ./foo.sh?



MYPATH_TO=~"/Documents 2/temp"
echo ~
echo "$MYPATH_TO"
mkdir "$MYPATH_TO"


when run in /home/mint/Documents 2 creates /home/mint/Documents 2/~/Documents 2/temp (echo outputs /home/mint ~/Documents 2/temp). I have read Why doesn't the tilde (~) expand inside double quotes? and put ~ outside of quotes, still does not expand, why?



ADDED: it does not expand because it is quoted in mkdir, but then how to script if I expect both spaces and symbols like ~ in path?



ADDED 2:
when I tried mkdir w/out quotes:



MYPATH_TO=~"/Documents/temp"
mkdir $MYPATH_TO


I got error mkdir: cannot create directory ‘~/Documents/temp’: No such file or directory. Why? I have Documents in my home. I'm lost...



System: Linux Mint 19.2










share|improve this question





























  • Use $HOME instead of ~; then you don't have to worry about expansion.

    – ajgringo619
    4 secs ago


















0

















Why ~ does not expand in $ ./foo.sh?



MYPATH_TO=~"/Documents 2/temp"
echo ~
echo "$MYPATH_TO"
mkdir "$MYPATH_TO"


when run in /home/mint/Documents 2 creates /home/mint/Documents 2/~/Documents 2/temp (echo outputs /home/mint ~/Documents 2/temp). I have read Why doesn't the tilde (~) expand inside double quotes? and put ~ outside of quotes, still does not expand, why?



ADDED: it does not expand because it is quoted in mkdir, but then how to script if I expect both spaces and symbols like ~ in path?



ADDED 2:
when I tried mkdir w/out quotes:



MYPATH_TO=~"/Documents/temp"
mkdir $MYPATH_TO


I got error mkdir: cannot create directory ‘~/Documents/temp’: No such file or directory. Why? I have Documents in my home. I'm lost...



System: Linux Mint 19.2










share|improve this question





























  • Use $HOME instead of ~; then you don't have to worry about expansion.

    – ajgringo619
    4 secs ago














0












0








0








Why ~ does not expand in $ ./foo.sh?



MYPATH_TO=~"/Documents 2/temp"
echo ~
echo "$MYPATH_TO"
mkdir "$MYPATH_TO"


when run in /home/mint/Documents 2 creates /home/mint/Documents 2/~/Documents 2/temp (echo outputs /home/mint ~/Documents 2/temp). I have read Why doesn't the tilde (~) expand inside double quotes? and put ~ outside of quotes, still does not expand, why?



ADDED: it does not expand because it is quoted in mkdir, but then how to script if I expect both spaces and symbols like ~ in path?



ADDED 2:
when I tried mkdir w/out quotes:



MYPATH_TO=~"/Documents/temp"
mkdir $MYPATH_TO


I got error mkdir: cannot create directory ‘~/Documents/temp’: No such file or directory. Why? I have Documents in my home. I'm lost...



System: Linux Mint 19.2










share|improve this question
















Why ~ does not expand in $ ./foo.sh?



MYPATH_TO=~"/Documents 2/temp"
echo ~
echo "$MYPATH_TO"
mkdir "$MYPATH_TO"


when run in /home/mint/Documents 2 creates /home/mint/Documents 2/~/Documents 2/temp (echo outputs /home/mint ~/Documents 2/temp). I have read Why doesn't the tilde (~) expand inside double quotes? and put ~ outside of quotes, still does not expand, why?



ADDED: it does not expand because it is quoted in mkdir, but then how to script if I expect both spaces and symbols like ~ in path?



ADDED 2:
when I tried mkdir w/out quotes:



MYPATH_TO=~"/Documents/temp"
mkdir $MYPATH_TO


I got error mkdir: cannot create directory ‘~/Documents/temp’: No such file or directory. Why? I have Documents in my home. I'm lost...



System: Linux Mint 19.2







bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question



share|improve this question








edited 37 secs ago







Marisha

















asked 26 mins ago









MarishaMarisha

1596 bronze badges




1596 bronze badges
















  • Use $HOME instead of ~; then you don't have to worry about expansion.

    – ajgringo619
    4 secs ago



















  • Use $HOME instead of ~; then you don't have to worry about expansion.

    – ajgringo619
    4 secs ago

















Use $HOME instead of ~; then you don't have to worry about expansion.

– ajgringo619
4 secs ago





Use $HOME instead of ~; then you don't have to worry about expansion.

– ajgringo619
4 secs ago










0






active

oldest

votes













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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
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%2f545624%2fbash-how-to-script-if-i-expect-both-spaces-and-symbols-like-in-path-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown


























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

















draft saved

draft discarded



















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f545624%2fbash-how-to-script-if-i-expect-both-spaces-and-symbols-like-in-path-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown









Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...