nkk
Android Expert
So I am just learning bash, and I had to make a program that simulates the output of a valve controlled steam heater. My output is of a time (in this script just the counter of the while loop), three temperature readings, and a string indicating if the valve state was changed during that loop interation. The output is of the form:
Since this is just a random output generator (for testing of my analysis program, not for any real use), the temps are all just random numbers,
Here is the script:
When I run it, I get:
So...can anyone help me? If you need any more info about the code (I thought the comments were enough to get the gist of it), please ask. You are doing me a huge favor.
Thanks
Nkk
Code:
int.int.int,int,string
which is equilivant to
timer,temp1,temp2,temp3.string to see if valve state was changed
Since this is just a random output generator (for testing of my analysis program, not for any real use), the temps are all just random numbers,
Here is the script:
Code:
#!/bin/bash
#some variables...
CLOSEVALVE='the valve was closed'
OPENVALVE='the valve was opened'
COUNTER=0
#make the necessary files
#delete the old file if it exists
if [ -e output.csv ]; then
rm output.csv
fi
#make a new one
touch output.csv
#Generate the actual output for a simulated 25000 loops
while [ $COUNTER -lt 25000 ]; do
#generate the random temps (three ofthem)
# between 40 and 80
T_ONE=$[ ( $RANDOM % 41 ) + 40 ]
T_TWO=$[ ( $RANDOM % 41 ) + 40 ]
T_THREE=$[ ( $RANDOM % 41 ) + 40 ]
TOGGLE_VALVE=$[ ($RANDOM % 2 ) ]
#Echo the random values with commas to the output file (a CSV)
echo -ne $COUNTER >> output.csv
echo -ne ',' >> output.csv
echo -ne $T_ONE >> output.csv
echo -ne ',' >> output.csv
echo -ne $T_TWO >> output.csv
echo -ne ',' >> output.csv
echo -ne $T_THREE >> output.csv
#check to see if should echo valve change string idicnator
if [ ( $TOGGLE_VALUE -eq 0 ) ]; then
echo -ne ',' >> output.csv
echo -ne $CLOSEVALVE >> output.csv
fi
if [ ( $TOGGLE_VALUE -eq 1 ) ]; then
echo -ne $OPENVALVE >> output.csv
fi
#send in the newline character
echo -ne '\n' >> output.csv
#increment the counter
let COUNTER=COUNTER+1
done
When I run it, I get:
Code:
'/home/myName/Dropbox/Workspaces/Heating-System-Programs/random_simulated_ouput_generator/randomInfoGenerator.sh'
/home/myName/Dropbox/Workspaces/Heating-System-Programs/random_simulated_ouput_generator/randomInfoGenerator.sh: line 46: syntax error near unexpected token `$TOGGLE_VALUE'
/home/myName/Dropbox/Workspaces/Heating-System-Programs/random_simulated_ouput_generator/randomInfoGenerator.sh: line 46: `if [ ( $TOGGLE_VALUE -eq 0 ) ]; then'
So...can anyone help me? If you need any more info about the code (I thought the comments were enough to get the gist of it), please ask. You are doing me a huge favor.
Thanks
Nkk