shell scripting errors when assigning value to vars

sullise

Verified User
Joined
Mar 4, 2004
Messages
519
Ok..sue me, I'm a noob when it comes to shell scripting...help me please!!!

This is a portion of a script I'm working on:

curip = "0.0.0.0"
attempts = 0

cat tempout | \
while read line
do
if [ "$line" != "$curip" ]
then
curip = "$line" <-- line 16
if [ $attempts -gt 4 ] <--- line 17
then
echo $line " was found 5 times"
fi
attempts = 0 <--- line 21
fi
attempts = $attempts + 1 <-- line 23
done

I'm getting these errors:

line 16: curip: command not found
line 17: [: -gt: unary operator expected
line 21: attempts: command not found
line 23: attempts: command not found

tempout contains a sorted list of IP's that the loop is supposed to go thru and count and if there are 5 or more of a single IP, output it.

I did an set -x before the top assignments and they are failing as well with "command not found".

I thoroughly confused. :(
 
Hello,

Does this script have the shebang line, the #!/bin/bash, on its first line?

Good luck, Phil.
 
LOL..yes it does, I just didn't paste it here. First part of script that creates the tempout file works fine. This is just a small routine in it that's not working.
 
Ok...here's a very primal example of me losing my mind.

PHP:
 [root@da01 scripts]# ./test.sh
./test.sh: line 3: X: command not found

[root@da01 scripts]# cat test.sh
#!/bin/bash

X = "something"

echo ${X}

exit 0
 
Try:

set X = "something"

or to keep it after the shell script is done:

export X = "something"

and see if that works.

Jeff
 
remove the spaces and it'll work

Code:
[getup@aquila getup]$ ./foobar
Echo content of $foo
bar
[getup@aquila getup]$ cat foobar
#!/bin/bash
foo="bar"
echo "Echo content of \$foo"
echo $foo
 
getUP said:
remove the spaces and it'll work

Code:
[getup@aquila getup]$ ./foobar
Echo content of $foo
bar
[getup@aquila getup]$ cat foobar
#!/bin/bash
foo="bar"
echo "Echo content of \$foo"
echo $foo

You know, I swore I tried that..lol..thanks. I"m used to PHP and other languages that I completely overlooked that bash doesn't like spaces in assignment statements...lol.

Thanks for the help, got everything working like a charm now.
 
Back
Top