[comp.unix.xenix] shell problem

raanan@bc-cis.UUCP (Raanan Herrmann) (03/19/88)

	An application I wrote in shell should accept a unix command 
from a user and execute it. The solustion should be:
	read l
	exec $l

	This does not work when $l contain a commands with parameters
(eg. "ls -l") as the error generated is "command not found", and does
not work when the command contain ";" (eg. "ls -l;who").
 
	My solution was;
	read l
	echo $l>tmp$$
	exec tmp$$
 
	But, I don't like this solution - any better ideas. PLEASE, also
e-mail your answer to me, to ron@jkfmny.uucp
-- 
------------------------------------------------------------------------
Ron Herrmann  (jkfmny!ron, ron@jkfmny.UUCP raanan@bklyncis.BITNET)

greg@csanta.UUCP (Greg Comeau) (04/05/88)

>An application I wrote in shell should accept a unix command 
>from a user and execute it. The solution should be:
>	read l
>	exec $l
>My solution was;
>	read l
>	echo $l>tmp$$
>	exec tmp$$

The ls -l should work, but the ls -l;who will not because the ';' is a shell
construct that needs to be intepreted (that is, $l only results in a string,
what you want to do is force the shell to scan the line again after
substitutions).  You can make this happen by using:
        eval $l  (or eval exec $l)