Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tilde expansion in environment variable

In my .sh file, I have this, cp $file $SOME_PATH, while $SOME_PATH is exported as export SOME_PATH="~/path/to/path/". But when I ran this .sh file, I got error message saying like no such "~/path/to/path/" exists. I replaced ~ as $HOME, then the error was gone. So what's up here with the tilde?

Thanks in advance.

like image 799
dutor Avatar asked Oct 21 '10 03:10

dutor


2 Answers

use

SOME_PATH=~/path/to/path/

if you path have spaces, quote it

SOME_PATH=~/"path with spaces"
like image 124
ghostdog74 Avatar answered Oct 01 '22 19:10

ghostdog74


Remove the quotation marks on your export:

export SOME_PATH=~/path/to/path/
like image 38
chrisaycock Avatar answered Oct 01 '22 19:10

chrisaycock