I have this script which works fine
#!/bin/bash
if [ $# -lt 1 ]
then
echo "USAGE: `basename $0` username"
exit 1
fi
logins=`last | grep $1`
times=`echo "$logins" | awk '{print $10}'`
timesCleared=`echo "$times" | sed -e 's/(//' -e 's/)//'`
minutes=`echo "$timesCleared" | awk -F: '{ print $1*60+$2}'`
total=0
for m in $minutes
do
total=$(( $total + $m ))
done
echo $total > out.txt
cat out.txt
but, for an example, when i try this command in the interactive shell it doesn't work ( echo $minutes gives a different output):
echo "in 02:16 00:28 00:16 00:25 02:44 00:09" | awk -F: '{ print $1*60+$2;}'
it prints 16
if i write echo $minutes in the scripts it gives me the right output:
0 136 28 16 25 164 9
Does anyone know why is this?
indoes not make sense as a number, so is evaluated as zero. (Yes, there is a numeric suffix, but this is what's going on here.)3+23:27.