Greetings! A shell script question: Can anyone tell me the pros & cons of coding your shell scripts to stay in-process instead of spawning a child process when needed? For example, ${VARIABLE##*/} instead of `basename $VARIABLE` I'm trying to use the former as much as possible now but I wasn't exactly sure if that is better, not so safe or just doesn't matter. Thanks! -- Gary
On Tue, Jul 23, 2002 at 10:05:27AM -0400, Gary J. Hanley wrote:
Can anyone tell me the pros & cons of coding your shell scripts to stay in-process instead of spawning a child process when needed?
The ones that immediately come to mind: Pro: You don't need to use extra resources to get the job done Con: It's not directly portable to other platforms /bin/sh on Linux is really bash. /bin/sh everywhere else that I know of is just sh and doesn't have the capabilities. If you want to be portable, don't rely on built-ins. If you don't care, use built-ins. For example: T=/path/to/file echo $T ${T##*/} Linux: $ sh t /path/to/file file Solaris: $ sh t t: bad substitution -- Randomly Generated Tagline: "...and scantily clad females, of course. Who cares if it's below zero outside" (By Linus Torvalds)
On Tue, 23 Jul 2002, Theo Van Dinter wrote:
Pro: You don't need to use extra resources to get the job done
Right. I guess that was obvious but I thought I'd ask anyway in case that wasn't as apparent as I saw it.
Con: It's not directly portable to other platforms
Good point. I do most of my shell scripting at work on Solaris and portability isn't an immediate issue, but something to be aware of anyway.
participants (2)
-
Gary J. Hanley
-
Theo Van Dinter