Score:0

'cd' doesn't work with the value, received from 'read' statement in shell script

mq flag

I wrote shell script, where I ask for input from the user:

read -p "Please enter the value" VALUE

But when I try to cd into $VALUE, received from read, I get an error:

bash: cd: ~/omg/: No such file or directory

Using both the shell script and the terminal, if I get the path from the read statement, then cd fails:

~$ read -p "ENTER THE PATH?!: " OMG
ENTER THE PATH?!: ~/omg/
~$ cd $OMG
bash: cd: ~/omg/: No such file or directory

However, if I assign the same text to a variable, then the cd command works:

~$ x=~/omg/
~$ cd $x
~/omg$

Why does it happen?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.