Skip to main content

Thread: [BASH] tilde doesn't expand from user input?


i learning bash scripting, , want have user type in path directory , allow use of ~

code:
echo 'type path somedir' read -e -p "> " path path=${path//\~/$home} echo 'your path:' echo $path
however, seems tilde charecter cannot replaced??

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.
code:
read -ep 'type path somedir ' path eval echo path: $path
moreover, tilde not expands $home. e.g. ~user means home directory of user, ~+ = $pwd, ~- = $oldpwd, , on.

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

Popular posts from this blog

Some mp4 files not displaying correctly (CS6)

Thread: Samba is not authenticating with LDAP