LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   stuck on bash variable "expansion"? (https://www.linuxquestions.org/questions/linux-software-2/stuck-on-bash-variable-expansion-665112/)

vornox00 08-24-2008 07:40 PM

stuck on bash variable "expansion"?
 
First, hello everyone. I use this site a lot, but I don't know what I'm doing wrong, so asking the right questions eludes me. I've googled 'variable expansion' & a few other phrases, but I don't really know what to search for. The posts I found here at LQ ("Click Here to Find Similar Threads") shows more stuff I don't yet understand. I want to make a function in this script to read a user's decision about which site to visit - there are choices 1 to 5, and 6 is exit.
Code:

visit_sites()        {
        echo "\v Which site?\n"
        choice=" \n 1. blah \n 2. blah \n 3. blah \n 4. blah \n 5. blah \n 6. Quit."
        echo " Choose from 1 to 6 & hit Enter: \n $choice\n"
        read site
        case $site in
            1)  $site="blah"
            2)  etc., thru 5
            6)  echo "\v Auf wiedersehen.\n"
                exit 0
                ;;
        esac
}

These variants (& many snipped for the sake of space)
"blah"___$"{blah}"___"{blah}"___$(blah)___$("blah")___$"(blah)"___'blah'___$'{blah}'___'{blah}'___$' blah'___$('blah')___$'(blah)'
& each of these prefaced with eval, but they all yield:
./test.sh: 59: 1=whatever i tried above: not found
I've also tried if/elif instead of a case but get the same error. I don't know what I'm doing wrong. I want that 1 (and 2 to 5) to become a FQDN, and pass it to the next function, get_browser(), even though $site has already been assigned 1 (or 2 to 5) as a value.
What should I read to learn how to do this?
Thanks.

32-bit Athlon, Ubuntu 8.04-1

matthewg42 08-24-2008 08:30 PM

When assigning to a variable, do not prefix the name with $.

i.e.
Code:

site="whatever"    # good
$site="whatever"    # bad

The $ is used only when taking the value of the variable, i.e.
Code:

echo "you chose $site"    # good
echo "you chose site"    # bad (will just print literal string "you chose site")


vornox00 08-24-2008 09:06 PM

thanks for your patience
 
doh! :rolleyes: I'm a genius. Thanks!!


All times are GMT -5. The time now is 02:10 AM.