Sunday, May 12, 2024
50
rated 0 times [  50] [ 0]  / answers: 1 / hits: 16247  / 2 Years ago, tue, august 2, 2022, 10:54:37

I'm trying to extract the different part of the Nvidia cuda library installer. I'm using the following command:



mkdir ~/Downloads/nvidia_installers
./cuda_6.5.14_linux_64.run -extract=~/Downloads/nvidia_installers


And I get the following message:



ERROR: extract: path must be absolute.


And when I type the command with the literal address of my home it work perfectly.



./cuda_6.5.14_linux_64.run -extract=/home/likewise-open/XXX/username/Downloads/nvidia_installers


I'm confused shouldn't ~ be the same of /home/likewise-open/XXX/username?



Tested:



./cuda_6.5.14_linux_64.run -extract=$HOME/Downloads/nvidia_installers


and it works, but I don't know why it doesn't allow ~


More From » command-line

 Answers
7

Bash only expands a ~ if it's the beginning of a word. You can see this between the following commands:



$ echo -extract=~/test
-extract=~/test

oli@bert:~$ echo -extract ~/test
-extract /home/oli/test


Bash looks for standalone ~ characters and ~/ for this substitution. No other combination or quoted version will work.



$HOME works because variable substitutions are more robust (the $ is a special character whereas ~ is very much less so):



$ echo Thisisastring${HOME}awrawr
Thisisastring/home/oliawrawr


While we're talking about ~, it actually has another couple of other substitution uses:




  • ~+ the current working directory (read from $PWD)

  • ~- the previous working directory (read from $OLDPWD)



As with plain ~, these can have additional paths tacked on the end, and again, these have to be the prefix to a word or Bash will ignore them.



You can read more about this in man bash | less -p ' Tilde'


[#23469] Tuesday, August 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
torlim

Total Points: 408
Total Questions: 113
Total Answers: 110

Location: Estonia
Member since Wed, May 27, 2020
4 Years ago
torlim questions
;