I’m building a shell script that is checks the existence of log files in a loop. The log files I’m trying to open are named like this: access_log-%02d00-%02d59 with %02d being an hour. In perl I could just say "access_log-${hour}00-${hour}59". But how do I do that in shell script? Here’s my code. It doesn’t work because it thinks the var name would be $HOUR00 and $HOUR59.
for HOUR in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23; do
if [ -e tmp/access_log-$HOUR00-$HOUR59 ]; then
# do stuff here
fi
done
I figured it out myself. I works just the same as in perl.
${HOUR}00does the trick.