Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!csd4.milw.wisc.edu!leah!bingvaxu!sunybcs!boulder!stan!dce From: dce@Solbourne.COM (David Elliott) Newsgroups: comp.unix.wizards Subject: sh functions with "local variables" Message-ID: <1397@marvin.Solbourne.COM> Date: 7 Jun 89 03:10:48 GMT Reply-To: dce@Solbourne.com (David Elliott) Organization: Solbourne Computer Inc., Longmont, Colorado Lines: 36 References: Here's an interesting problem for all of you sh/ksh wizards out there. I normally write shell scripts using a template like this: main() { ... } sub1() { ... } ... main ${1+"$@"} # don't ask, just use it Now, in modern versions of sh (post SVR2, I think), function parameters are local to the function, but there's no way to have local variables otherwise. Let me clarify this a little. Yes, if you force a subshell, either by parenthese or redirection, the changes in the subshell don't affect the main thread, but that's not really what I'm looking for. Now, if the function doesn't have any arguments, or if you can use the arguments early and get rid of them, you can use "set" to put values in $1-$9, which is one way to have local variables. Still, real local variables would be great. Of course, arrays would be nice, too. Maybe it's time to implement sh++? -- David Elliott dce@Solbourne.COM ...!{boulder,nbires,sun}!stan!dce