| Valerie Aurora ( @ 2008-12-03 18:05:00 |
| Entry tags: | programming |
bash lesson of the day
So I'm running a command in a for loop in bash:
SECONDS=1
for i in 1 2 3 4; do
../my_test -S "${SECONDS}"
done
And for some damn reason, the test runs for 1 second on the first loop, then 2 seconds on the second loop, then 4 seconds on the next, etc. WTF?
Ten minutes of debugging output later, I finally type "man bash":
SECONDS
Each time this parameter is referenced, the number of seconds
since shell invocation is returned. If a value is assigned to
SECONDS, the value returned upon subsequent references is the
number of seconds since the assignment plus the value assigned.
If SECONDS is unset, it loses its special properties, even if it
is subsequently reset.
Geez.