1834254 Members
1994 Online
110066 Solutions
New Discussion

shell scripting

 
baiju_3
Esteemed Contributor

shell scripting

Hi ,

I want to achive a pause in my script.It doesnot take the pause and loop contniues to run.

I have done it in similar way long back , but now it is not working .

Is there any way to insert a pause in a loop ?

Please reply ,
Thanks in advance,
BL.

#!/bin/ksh

cat list |while read usr ;do
echo "current user is $usr"
while true
do
echo "I am in while loop"
echo "Press ny key"
read nothing
done
done


Good things Just Got better (Plz,not stolen from advertisement -:) )
7 REPLIES 7
c_51
Trusted Contributor

Re: shell scripting

your "cat list|while read" and "read nothing" are both reading from stdin and will read from the date from "cat list |"

you'll need to do something like this

cat list |&

while read -p while read
do
echo "current user is $usr"
while true
do
echo "I am in while loop"
echo "Press ny key"
read nothing
done
done
c_51
Trusted Contributor

Re: shell scripting

sorry for my typo's

should be

read the data from "cat list |"

and

while read -p usr
baiju_3
Esteemed Contributor

Re: shell scripting

Hi

I did change the loop begning like this and it started working,

for usr in `cat list`
do
while :
do
......

Thanks,
BL.
Good things Just Got better (Plz,not stolen from advertisement -:) )
Biswajit Tripathy
Honored Contributor

Re: shell scripting

> Is there any way to insert a pause in a loop ?

What do you mean by pause? Do you mean that
the script should wait for any user key input and
once user presses any key, it should continue or
just pause for a short time (like 2 Sec)?

If you want to wait for any use key stroke, then do
this:
---
while true
do
echo "I am in while loop"
echo "Press any key"
read
done
----

If you want to pause for short time (like 2 Sec),
then do this:
--
while true
do
echo "I am in while loop"
echo "Press any key"
sleep 2
done
----

Did I understand the question correctly?

- Biswajit

:-)
Biswajit Tripathy
Honored Contributor

Re: shell scripting

Never mind, I did misunderstand your question :-(
- Biswajit
:-)
john korterman
Honored Contributor

Re: shell scripting

Hi,
a simple approach:

#!/usr/bin/sh
while read user
do
echo "current user is $user"
echo "Press any key:\c"
read nothing done <$1

Run the above loop.sh with your input file as $1, e.g.:
# loop.sh infile

regards,
John K.
it would be nice if you always got a second chance
Gordon  Morrison
Trusted Contributor

Re: shell scripting

This is a little function that I have been using for years:

pause()
{
read junk?'Press RETURN to continue.'
}


e.g.
while true
do
echo "Looping."
pause
echo "Here we go again..."
done
What does this button do?