Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-24-2008, 08:40 PM   #1
LQ Newbie
Registered: Aug 2008
Posts: 2

Rep: Reputation: 0
Question 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.
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
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:
./ 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?

32-bit Athlon, Ubuntu 8.04-1
Old 08-24-2008, 09:30 PM   #2
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
When assigning to a variable, do not prefix the name with $.

site="whatever"     # good
$site="whatever"    # bad
The $ is used only when taking the value of the variable, i.e.
echo "you chose $site"    # good
echo "you chose site"     # bad (will just print literal string "you chose site")

Last edited by matthewg42; 08-24-2008 at 09:32 PM.
Old 08-24-2008, 10:06 PM   #3
LQ Newbie
Registered: Aug 2008
Posts: 2

Original Poster
Rep: Reputation: 0
thanks for your patience

doh! I'm a genius. Thanks!!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 07:15 PM
variable expansion in bash coolhandluke1 Programming 4 01-09-2008 04:45 PM
Variable expansion in BASH champak Programming 5 11-26-2007 03:44 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 02:45 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration