Thread: [BASH] tilde doesn't expand from user input?
i learning bash scripting, , want have user type in path directory , allow use of ~
however, seems tilde charecter cannot replaced??code:echo 'type path somedir' read -e -p "> " path path=${path//\~/$home} echo 'your path:' echo $path
edit:
fixed code, thanks.
try
code:path=${path/#\~/$home}
actually, there's not point in such substitution can force tilde expansion eval:edit. dangerous, see vaphell's post below.
moreover, tilde not expands $home. e.g. ~user means home directory of user, ~+ = $pwd, ~- = $oldpwd, , on.code:read -ep 'type path somedir ' path eval echo path: $path
note code has other problems, too: no prompt after read -p , single quotes in last line (shell parameters expanded inside double quotes).
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [BASH] tilde doesn't expand from user input?
Ubuntu
Comments
Post a Comment