0

When I do this, it works perfectly and downloads the file at the required path.

wget -O ~/Temp/my.file "https://github.com/sometool/releases/latest/download/the.file"

But when I do this:

PATH="~/Temp/my.file"
wget -O $PATH "https://github.com/sometool/releases/latest/download/the.file"

It says:

~/Temp/my.file: No such file or directory

I've tried with or without quotes, wrapped in $(echo $PATH), always the same error.

I am using MacOS Terminal.

  • 2
    Does this answer your question? Expansion of tilde in zsh (assuming it's a ZSH script). – Kulfy Sep 07 '21 at 15:28
  • @Kulfy The answer there states, correctly, that the code posted in the question should work as intended. – Gilles 'SO- stop being evil' Sep 07 '21 at 15:49
  • 3
    The code you posted here would not have the effect you describe. Not only because ~ is expanded there, so you would see the path to your home directory there, but because PATH is a system variable that indicates where to find commands, so the actual effect of the code you posted would be zsh: command not found: wget. Please copy-paste what you actually typed. Preferably in a new terminal tab, since you might have done some weird reconfiguration in that shell before the part you posted. – Gilles 'SO- stop being evil' Sep 07 '21 at 15:51
  • @Gilles Did you mean set -o magicequalsubst won't make any difference? – Kulfy Sep 07 '21 at 15:53
  • Indeed @Gilles'SO-stopbeingevil'. I edited my question. I had double quotes around the path in the variable assignment. Removing these did fix the problem. – Jérémy Quentin Sep 07 '21 at 15:54
  • Remove the double quotes around the tilde. Your revised question is a duplicate of https://unix.stackexchange.com/questions/146671/does-always-equal-home/146697#146697 . See also https://unix.stackexchange.com/questions/151850/why-doesnt-the-tilde-expand-inside-double-quotes – Gilles 'SO- stop being evil' Sep 07 '21 at 16:24
  • 1
    @Kulfy magicequalsubst only affects equal signs that are not variable assignments. PATH=… is a variable assignment, so an unquoted tilde at the beginning is always expanded. – Gilles 'SO- stop being evil' Sep 07 '21 at 16:25
  • This could also happen if the folder does not exist (i.e. if there's a typo in the folder name) – ViliusK Nov 22 '22 at 07:34

1 Answers1

0

As mentioned in the comments, removing quotes in the variable declaration fixed it:

PATH=~/Temp/my.file

More details provided at:

Does ~ always equal $HOME

Why doesn't the tilde (~) expand inside double quotes?