Possible Duplicate:
How can I do command line integer & float calculations, in bash, or any language available?
I would like to simply re-assign a variable (to be specific, increment it by 0.050) in a bash script. In the following script that I wrote, i is an (integer) index, and mytime is a decimal/double/float number. "ps" (picosecond) is the unit of time that I am using in my calculations.
#!/bin/bash
mytime = 0.000
for i in {1..3}
do
echo "$i: $mytime ps"
mytime = mytime + 0.050
done
But, when I run this script using bash test.sh, I get these error messages:
test.sh: line 2: mytime: command not found
1: ps
test.sh: line 6: mytime: command not found
2: ps
test.sh: line 6: mytime: command not found
3: ps
test.sh: line 6: mytime: command not found
Why does it seem to be interpreting mytime as a command or a function, instead of as a variable? Can you please help me to correct this?
bashgrammar. You should go read a quick intro or else you will be frustrated to no end by so many different syntax and logic errors. Your assignment syntax is wrong (no spaces allowed, but you need to understand shell grammar to know why), and bash doesn't do floating point math, nor is that the correct syntax for arithmetic expansion. Teachingbashis beyond the scope of a single answer. Try the Wooledge wiki guide for starters. – jw013 Jun 30 '12 at 17:22