Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a shell script where counter needs to be set for input paramter and do action once the count reaches to 5. The problem is there could be n number of input parameter and action should also be dependent on time ... Lets suppose if within 60 mins if count reaches upto 5 then which ever action i want to do .......

I found somthing like below but there is no explanation in this programm.....Please help...

echo "Enter a series of lines of numbers separated by spaces."
read LIST
IFS=" "
for VALUE in $LIST ; do
    eval export ARRAY_$COUNTER
    COUNTER=$(expr $COUNTER '+' 1) # More on this in Paint by Numbers

# print the exported variables.
echo "Printing values."
while [ $COUNTERB -lt $COUNTER ] ; do
    echo "ARRAY[$COUNTERB] = $(eval echo '$'ARRAY_$COUNTERB)"
    COUNTERB=$(expr $COUNTERB '+' 1) # More on this in Paint by Numbers


share|improve this question
This looks very similar to this question: unix.stackexchange.com/questions/57257/… – DarkHeart Dec 1 '12 at 3:31

If your script is going to be called multiple times then you need to keep the counter in some external persistent form, a environment variable or file. In this case ARRAY_n is exported for this purpose.

share|improve this answer
Thanks for the response... Can I use the same srcipt as I am not sure i searched it from some link...... – user28011 Nov 30 '12 at 4:38
I have tried below way but its not working as its again and again showing as count as 1....x="$device" count=0 for device_count in $x do count=expr $count + 1 echo "pe_[$device_count] count $count" >> ${LOGFILE} if [ count -eq 5 ]; then echo "email " >> ${LOGFILE} fi done – user28011 Nov 30 '12 at 10:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.