PDA

View Full Version : IT bods shell script help



Nathan_200sx
19-03-2003, 14:45
How the hell do you multiply a variable in a bash script?

I've tried this

a=$(tail -100 /var/log/messages |grep -c a)
b=$((a*5))
echo b



but I just get back *5 : syntax error operand expected : (error token is "*5")

I dont realy neead to count how many "a's" there are in the last 100 lines of messages and times it by 5 I just need to find out how to multiply a variable from within a script :mad: :mad:

Cthugha
19-03-2003, 15:00
a=$(tail -100 /var/log/messages |grep -c a)
((b=a*5))
echo $b


say thanks to the unix guru`s here

Phil L
19-03-2003, 15:18
dunno about bash but in bourne shell, expressions are done using:

x='expr 2 * 5'

Nathan_200sx
19-03-2003, 15:34
Originally posted by Phil L
dunno about bash but in bourne shell, expressions are done using:

x='expr 2 * 5'

bash is Bourne Again Shell so i should work but doesnt niether does Cthugha's suggestion

:(

Tried

b=`$a \* 5`

but still no luck, it got rid of the syntax error and came back with *:command not found :mad: :mad: :(

Nathan_200sx
19-03-2003, 15:42
Yay sorted it by getting angry and trying everything.

Should have been:-

b=$((a * 5))


Which is basicaly the same as what Cthugha said but I must have typed it wrong in my rage

:rolleyes: :rolleyes:

Nathan_200sx
19-03-2003, 15:46
oh and thanks to the unix gurus at Cthugha's work