Subject: Re: [ast-users] sh as ksh builtin?
--------
> Hello,
>
> after reading a lot about ksh builtin commands was wondering if ksh
> can have itself as built-in.
>
> The usecase are scripts which have many lines (sometimes a few hundred
> or run them in loops) like sh -c 'execute something', each of them
> creating a new process, execute a few commands and then return again
> to the parent shell. Could ksh builtins help in such a scenario by
> making sh itself a builtin?
>
> I know there are alternatives like replacing the sh -c '' lines with
> subshells or other constructs but using builtins would require almost
> no changes in the scripts and may be preferable in this case.
>
I am not sure what you would gain.
On the other hand, ksh is written as a shared library that can
be built into other commands. That is how dtksh and tksh work.
You could of course write a shell function that behaves like
ksh by doing the option parsing and then used read and eval to
do the execution.
Or even simpler, you could catch sh -c lines, with
function sh
{
if [[ $1 == -c ]]
then shift
( eval "$@")
else command sh -c "$@"
fi
}
but I don't know how much benefit there would be. I addition all variables
will be seen in the subshell, not just export variables.
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users