Reputation: 372
I am making a shell that resembles Command Prompt (it is not finished) but it doesn't work. Here it is:
#!/bin/bash
VER=$(lsb_release -sr)
OS=$(lsb_release -si)
echo "Linux [Distro $OS Version $VER]"
echo "<c> None"
echo -n "${PWD}>"
read $cmd
eval $cmd
I am running on Crunchbang. When I run it:
crunchbang@crunchbang:~$ ./cmd.sh
Linux [Distro Debian Version 7.0]
/home/crunchbang>echo "abc"
crunchbang@crunchbang:~$
What it should be:
crunchbang@crunchbang:~$ ./cmd.sh
Linux [Distro Debian Version 7.0]
/home/crunchbang>echo "abc"
abc
crunchbang@crunchbang:~$
Even better:
crunchbang@crunchbang:~$ ./cmd.sh
Linux [Distro Crunchbang Version 11]
/home/crunchbang>echo "abc"
abc
crunchbang@crunchbang:~$
Upvotes: 0
Views: 128
Reputation: 239
You need to take the $ off the read line
read cmd
Bash is expanding the variable to nothing, and executing "read"
Upvotes: 1
Reputation: 80931
read $cmd
is incorrect. You meant read cmd
.
You only use $
to reference a variable, not name one.
Your input is likely ending up in $REPLY
.
Upvotes: 2