I'm currently learning Bash scripting from a book and the following example is given, but I think there is a typo in the variable assignment for the variable file.
Code:
$ cat test5
#!/bin/bash
# reading values from a file
file=“states” ( shouldn't this be file=`cat states` assuming you have a
text file with the list , doesn't this just assign the single
string states? )
for state in ‘cat $file’
do
echo “Visit beautiful $state”
done
$ cat states
Alabama
Alaska
Arizona
Arkansas
Colorado
Connecticut
Delaware
Florida
Georgia
$ ./test5
Visit beautiful Alabama
Visit beautiful Alaska
Visit beautiful Arizona
Visit beautiful Arkansas
Visit beautiful Colorado
Visit beautiful Connecticut
Visit beautiful Delaware
Visit beautiful Florida
Visit beautiful Georgia
$
Am I missing something here?
Last edited by fpmurphy; 05-05-2012 at 11:04 AM..
Reason: code tags please!
No quotes are needed in this case: file=states would suffice, but they won't hurt if they are the right double quotes, which is not the case here “” vs. ""
You are using are the wrong kind of double quotes. Either you copied it from somewhere instead of typing it at the keyboard, or typed it in Microsoft Word or something.
Code:
$ file=“states” # these are the wrong quotes
$ echo "$file"
“states”
$ file="states" # these are the right quotes
$ echo "$file"
states
Hello,
May be my post may look naive to many...but it isn't if you were to believe me.After, trying to learn programming in C for at least 5 years , I concluded that K & R is the best book to learn C, alas I took a lot of time to realize this.
So, I'm going to start learning how to program... (8 Replies)
Hello, I'm new to this forum, and I apologize in advance if I did something wrong here.
I am pretty stumped here as I am still getting the error message, "./comc1.sh: test: argument expected." after executing the script itself.
Here's the script file I modified:
I tried executing line 4... (1 Reply)
Hi is it me or is there a typo in the Sun Solaris man page for ps. I thought the option for listing a process by PID was just -p but on the clearcase server at work it reads: -
-ps proclist
Lists only process data whose process ID numbers are
given in proclist.... (5 Replies)
Hi
Sorry to post a bit of an "I'm an idiot" post, but I did a typing error and typed "ls 'l" instead of "ls -l". This seems to have made me enter some sort of mode or other that I can't seem to be able to get out of. The new line prompt is > (if that helps).
Sorry for posting such a... (1 Reply)
Hi everybody
I a new one
And I have just wanted to research on Sun Solaris
So can you help me what e-book to read ( and if can you give me the
direct address to load )
Thks so much (3 Replies)