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"