[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Running commands as "$@"
From: |
Greg Wooledge |
Subject: |
Re: Running commands as "$@" |
Date: |
Thu, 2 Feb 2023 11:24:33 -0500 |
On Thu, Feb 02, 2023 at 04:29:23PM +0100, Cristian Zoicas wrote:
> There was a mistake in my original question (I'm very sorry about that).
> I wanted to ask the question not for the script above, but for the following
> script (the entire message was relative to this script but by mistake I've
> left the eval in the question.)
>
> # ---- begin script runner.sh ----
> "$@"
> # ---- end script runner.sh ----
You will never, ever, under any circumstances, be able to pass variable
assignments to this.
This API is only suitable for chain-loading external commands, as in:
sh runner.sh mydb start password='apple sauce'
It's great for that. But you can't give it anything that the shell
has to process, like variable assignments, if/then/fi compound commands,
redirections, etc.
P.S. put a shebang in your script already.
#!/bin/sh
exec "$@"
Then you can run it directly without needing to type "sh " every time.
Re: Running commands as "$@", Greg Wooledge, 2023/02/02
Running commands as "$@" ( ERRATUM ), Cristian Zoicas, 2023/02/02