Set parent env with csh script

L. Mark Larsen lml at cbnews.ATT.COM
Wed Jan 11 09:30:29 AEST 1989


In article <1291 at uwbull.uwbln.UUCP> ckl at uwbln.UUCP (Christoph Kuenkel) writes:
# ...Bourne shell does it right, but attention, in
# 
# 	while <expr>; do
# 		<stmnt>
# 	done <io redirection>
# 
# <stmnt> is executed in a ``subrocess context'' due to the io redirection!
# So any variable assignement and/or environment setting is uneffective outside
# the while-loop.
# Any elegant solution to that?
# 
# christoph

By putting the loop into a function and redirecting at the function call, the
variables set in the function will still be in effect outside of the while
loop.  For example:

func ()
{
	while <expr>; do
		<stmnt>
	done
}
func <io redirection>

This works with sh.  Incidently, ksh does not share the "feature" of sh that
force while and for loops to be executed in a subprocess, so this kind of 
trick is not necessary.

Elegant?  You decide.

L. Mark Larsen
lml at atlas.att.com
att!atlas!lml



More information about the Comp.unix.wizards mailing list