本篇简要介绍shell script 中内部变量的使用。
1、$SECONDS
-----这个脚本已经运行的时间(以秒为单位).
#!/bin/bash
TIME_LIMIT=10
INTERVAL=1
echo
echo "Hit Control-C to exit before $TIME_LIMIT seconds."
echo
while [ "$SECONDS" -le "$TIME_LIMIT" ]
do
if [ "$SECONDS" -eq 1 ]
then
units=second
else
units=seconds
fi
echo "this script has been running $SECONDS $units."
sleep $INTERVAL
done
echo -e "\a"
exit 0