#!/bin/sh # # This file is in the public domain # Process options - or how to do getopt(3) in shell scripts ;-) DEBUG=0 USAGE=0 while [ -n "$1" ] # Loop as long as $1 is nonempty do case $1 in -d) DEBUG=1 shift ;; -h) USAGE=1 shift ;; *) # If this is not the last argument, it's an # unknown option - complain. Otherwise it's # the positional argument, and we're done # with the loop. if [ -n "$2" ] # If $2 is nonempty, $1 is not last then echo ERROR: Unknown option $1 USAGE=1 shift else break fi ;; esac done if [ $USAGE = 1 ] then echo "Usage: delay [-d]" echo " delay -h" exit 1 fi # Loop, answering requests while : do # Read message IFS='=' while read ATR VAL && [ -n "$VAL" ] do IFS=' ' [ "int" = "$ATR" ] && DELAY=$VAL IFS='=' done IFS=' ' # Show debugging output if requested [ $DEBUG = 1 ] && echo "delay[$$]: delay=$DELAY" 1>&2 # Reply sleep $DELAY echo "int=$? " done