[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Running commands as "$@"
From: |
alex xmb ratchev |
Subject: |
Re: Running commands as "$@" |
Date: |
Thu, 2 Feb 2023 15:18:12 +0100 |
try with $*
i didnt read closly
just small suggestion
greetings
On Thu, Feb 2, 2023, 3:15 PM Cristian Zoicas <zoicas@medialab.sissa.it>
wrote:
> Hello all
>
> Let's assume the following script.
>
> # ---- begin script runner.sh ----
> eval "$@"
> # ---- end script runner.sh ----
>
> If we call this script with the following command line
>
> $ sh runner.sh ls -l
>
> the 'ls -l' command will be executed.
>
> Now, if a call the script with the commands
>
> $ sh runner.sh A=B
>
> we get the following errors:
>
> runner.sh: 10: runner.sh: A=B: not found
>
> Why the shell does not treat the first string in "$@" ('A=B'
> in these cases) as the first possibile token of command (which
> is an assignemnt)?
>
> In addition, the problem is NOT solved by using 'eval "$@"'.
> Apparently it works. For example the command
>
> $ sh runner.sh A=BCD
>
> works, but
>
> $ sh runner.sh A="B CD"
>
> gives an error. In this case the error (I think) comes
> from the way the expansion of "$@" is performed: eval has to evaluate the
> string "A=B CD", so it treats A=B as an assignemnt and 'CD' as
> a command.
>
> I am curios what is going on and if there is any possibility of
> running a command (any command, including an assignment) by using
> a very simple invocation (someting like eval "$@").
>
> Thank you in advance.
> Cristian Zoicas
>
>
>
Re: Running commands as "$@", Greg Wooledge, 2023/02/02