as the home directory?
I tried all 3 methods below but it just echos out the ~.
NAME="~/_root/repo/"
echo $NAME
echo "$NAME"
echo "${NAME}
as the home directory?
I tried all 3 methods below but it just echos out the ~.
NAME="~/_root/repo/"
echo $NAME
echo "$NAME"
echo "${NAME}
Have the shell expand the ~ before assigning it to NAME, by removing the quotes on the assignment statement.
NAME=~/_root/repo/
echo "$NAME"
There's no function for that. A tilde inside a string is just a tilde. You'll have to manually match and replace it with the value of $HOME:
var=${var}/
var=${var/#"~/"/"$HOME/"}
var=${var%/}
If you use 'eval', it interprets everything – it expands the tilde, but it also expands wildcards, it also expands variable substitutions, it also parses spaces, quotes, array syntax, and so on.
var="~/dir/file.txt"
eval "var=$var"
var="~/dir with spaces/file.txt"
eval "var=$var"
var="~/dir/file (1).txt"
eval "var=$var"
cd ~it knows to change directory to my home directory. – Sun - FE May 19 '19 at 22:22evalfor interpreting a whole command line as if "typed in". There isn't anything for performing certain individual expansion steps. – u1686_grawity May 19 '19 at 22:24echo $( eval echo $( echo ${NAME} ) )note the curly braces are different than the parenthesis – TOOGAM May 19 '19 at 23:27eval echo $NAMEalready. – u1686_grawity May 20 '19 at 04:23