Shell script help needed

Nick Crossley nick at ccicpg.UUCP
Thu Nov 24 10:57:01 AEST 1988


In article <1872 at loral.UUCP> jlh at loral.UUCP (Physically Pffft) writes:
>... about how to do things to a set of directories ...
>
>My problem is I don't know how to suspend a shell script like this, and then
>have it continue where it left off.  My only idea is to create a new shell
>('/bin/sh'), but I think this would be slower than snail snot.  Anyone
>have any ideas?  Thanks.
>
>-- 
>Jim Harkins		jlh at loral.cts.com
>Loral Instrumentation, San Diego

I do this kind of thing sufficiently often that I wrote a script to do it,
and I did use a nested shell.  It is fast enough for my needs; your mileage
may vary.  Note that handling signals is tricky - I don't guarantee correctness!
The script is quite small, so I include it below.  It works with sh and ksh;
I don't know about csh, but I see no reason why it should not work there also.

--------------  cut here  ---------------------------------------------------
:	SCAN  -  take actions throughout a directory tree
#	Usage:  scan [-c "command"] dir ...

if	[ X$1 = X-c ]
then	Command="$2"
	shift;  shift
else	Command='echo "Now in `pwd` - type EOF to continue" ; exec ${SHELL-ksh}'
fi

exec 7<&0
{ trap '' 2 ; exec find ${*-.} -type d -print ; } |
{
trap 'continue' 2
while	read i
do
	( trap 2 ; cd $i ; eval $Command ) 0<&7
done
}

echo "Scan finished"
--------------  cut here  ---------------------------------------------------
-- 

<<< standard disclaimers >>>
Nick Crossley, CCI, 9801 Muirlands, Irvine, CA 92718-2521, USA
Tel. (714) 458-7282,  uucp: ...!uunet!ccicpg!nick



More information about the Comp.unix.wizards mailing list