Why use $HOME over ~ (tilde) in a shell script?
Tilde expansion doesn’t work in some situations, like in the middle of strings like /foo/bar:~/baz
Tilde expansion doesn’t work in some situations, like in the middle of strings like /foo/bar:~/baz
~ is a bash-ism rather than a perl-ism, which is why it’s not working. Given that you seem to be on a UNIX-type system, probably the easiest solution is to use the $HOME environment variable, such as: if ( -e $ENV{“HOME”} . “/foo.txt” ) { print “yes ,it exists!” ; } And yes, I know … Read more
If the variable var is input by the user, eval should not be used to expand the tilde using eval var=$var # Do not use this! The reason is: the user could by accident (or by purpose) type for example var=”$(rm -rf $HOME/)” with possible disastrous consequences. A better (and safer) way is to use … Read more