long number most significant bit chopped off in shell script -
i assigning long value variable in shell script , trying calculations it, results negative sign numbers.
count=4 initial_value=128 final_value=18446744073709547520 step=$((($final_value - $initial_value) / ($count - 1))) value=$initial_value for((i=1; i<=count; i++)) start=`date +%s` myvariable=$(mysql $database -u $user -se "set global join_buffer_size = $value;query run") end=`date +%s` time=`echo "$end - $start" | bc` echo "$value $time" >> output.txt value=$(($value+$step)) mysqld restart done
the output of output.txt file this:
128 20 -1280 20 -2688 21 -4096 20
i can't tell shell script use unsigned long, didn't chop off number. how can fix it? thanks
your $final_value
larger max int bash arithmetic (which 9223372036854775807). use bc
instead:
count=4 initial_value=128 final_value=18446744073709547520 step=$(echo "($final_value - $initial_value) / ($count - 1)") value=$initial_value for((i=1; i<=count; i++)) start=$(date +%s) myvariable=$(mysql $database -u $user -se "set global join_buffer_size = $value;query run") end=$(date +%s) time=$(echo "$end - $start" | bc) echo "$value $time" >> output.txt value=$(echo "$value+$step" | bc) mysqld restart done
sample output (removed mysql commands copy):
128 0 6148914691236515925 0 12297829382473031722 0 18446744073709547519 0
Comments
Post a Comment