[Top][All Lists]

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

Re: Running commands as "$@"

From: Cristian Zoicas
Subject: Re: Running commands as "$@"
Date: Thu, 2 Feb 2023 17:35:37 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 SeaMonkey/2.53.3

For your "" you could pass the command with an extra layer of
quoting around it:

sh 'A="B    CD"'

And that will work with eval "$1" or eval "$*".  But it's terrible, just
like su is terrible.  It has precisely the same limitations, because it's
using precisely the same mechanism.

1. Yes, It's terrible. I want to avoid something like this.

2. There was a mistake in my original question and I am extremely sorry for 

   I wanted to ask the question for this script

   # ---- begin script ----
   # ---- end script ----

   and not for the one with "eval"

   I'm extremly sorry for this.

So... what do you *really* want?  Is "sh" a stand-in for some
kind of ssh-like or Docker-like tool, where you want to type a command
locally but run it in a different environment (different account, different
computer, different container, etc.)?

Or are you looking for something that will log your commands exactly as
they were typed (in a place that isn't shell history) before running them?

This last supposition is correct. It's not necessarly about logging commands, 
it may be.

Let's  assume that in a script I have a command:

    ls -l

Without making *any* modification to this line I want to put something in front 
it (a shell function for example) and have all the tokens that form that command
passed to the function and eventually executed. For example, for the command 
I would like to have something like this:

    echo "command $@: $?"

check_execution_status ls -l

This case works. But if I have this line


then it will not work for

check_execution_status A=B

But now I realize that even if it would work for this case, then it wouldn't 
work for
assignemtns like

check_execution_status A="B     C"

because the double quotes would be stripped from the string just before the 

Thank you for your answer.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]