tech-userlevel archive

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

Re: Shell Command Substitution and fork()



Hello Edgar,

so why don't you use PDKSH (/bin/ksh) or pkgsrc's ast-ksh instead of ash (/bin/sh) ? Even pkgsrc's GNU Bash would do.

I do x=`command` which is almost the same as $(command), using any KSH or BASH as interpreter. I don't really care about POSIX here as KSH and BASH syntax is much more powerful.

Pierre-Philipp

On 21/06/2016 20:46, Edgar Fuß wrote:
I have a shell script that makes heavy use of Command Substitution, i.e.
	x="$(some-command)"
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