tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Shell Command Substitution and fork()

I have a shell script that makes heavy use of Command Substitution, i.e.
The script takes several seconds to execute, mainly because Command 
Substitution takes place in a Subshell Environment and that usually means 
a fork().
However, the OS X^W^WmacOS ksh only takes tens of milliseconds for the same 
job, as does shells/ast-ksh from pkgsrc.
Unsurprisingly, the latter (I'm unable test for the former due to lack of 
ktrace or the like) doesn't fork.

Does anyone know how those ksh's achieve that? Are there any drawbacks? 
Could ash be taught the same thing?

Or can someone think of a POSIX-compliant way to put the output of a command 
(think printf) into a variable without Command Substitution? Unfortunately
	printf ... | read x
doesn't do the trick because POSIX allows (and most shells indeed do) 
execution of the tail-of-pipe in a Subshell Environment.

Home | Main Index | Thread Index | Old Index