Path: utzoo!attcan!uunet!ccicpg!nick From: nick@ccicpg.UUCP (Nick Crossley) Newsgroups: comp.unix.wizards Subject: Re: Shell script help needed Summary: I use nested shell Keywords: Suspend a foreach() loop? Message-ID: <41799@ccicpg.UUCP> Date: 24 Nov 88 00:57:01 GMT References: <1872@loral.UUCP> Reply-To: nick@ccicpg.UUCP (Nick Crossley) Organization: CCI CPG, Irvine CA Lines: 45 In article <1872@loral.UUCP> jlh@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@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