Some programs do not recognize tilde shortcut in filenames and expect full canonical paths, e.g. /home/dave/myfile.txt instead of ~/myfile.txt.

Is there a way to make bash replace ~ and ~user by full canonical paths anytime a tilde is used?

link|improve this question

58% accept rate
3  
Can you provide examples of commands where ~ isn't expanded by bash ? The shell should do it. Called programs do not need to interpret it. – jlliagre Nov 1 '10 at 8:26
Consider replacing ~ with $HOME as well. – frabjous Nov 1 '10 at 14:04
For example, some Perl scripts won't recognize paths with ~. So what I would like bash to do is explicitly expand the path, just like it auto completes when I hit the tab key. – David B Nov 1 '10 at 19:55
feedback

1 Answer

When you run a command in the Bash shell, like:

command ~/myfile.txt

the shell first makes the expansion of ~ (unless it's quoted) then it run the command with the result.

But it's true, some programs don't interpret the ~, for example:

$ cat "~/myfile.txt"
~/myfile.txt: No such file or directory

but this works insted:

nano "~/myfile.txt"

But this behavior is masked by the Bash expansion, so you don't need any further interpretation.

Maybe it's obvious, but note that if a program uses a configuration files and expects some paths in it, it's not a Bash duty expand them.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.