|
Home > Archive > Unix Shell > February 2005 > problem with executing commands from within the shell using a command string.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problem with executing commands from within the shell using a command string.
|
|
| dsingh2@stevens.edu 2005-02-28, 8:50 pm |
| Hello,
I am facing a problem with execution of commands from within the shell
script. The following is the trouble maker.
The command when executed from the prompt behaves as follows when the
host 'courage' is not available
$ ping -c1 -w1 courage >/dev/null 2>&1 || echo courage is down
courage is down
Now assume that the same text is in a script variable
EXEC_STR="ping -c1 -w1 courage >/dev/null 2>&1 || echo courage is down"
and i execute it by
exec $EXEC_STR or ` echo $EXEC_STR `
I get the following message
usage:
ping [-adDfLnoPqQrRv] [-c count] [-g gateway] [-h host] [-i interval]
[-I addr]
[-l preload] [-p pattern] [-s size] [-t tos] [-T ttl] [-w maxwait]
[-E policy] host
but if the the command in the string was as follows ...
EXEC_STR="ping -c1 -w1 courage"
the ping command works.
I need the command to behave normally with the above mentioned
execution string.
Your expert help is needed.
Thanks in advance.
| |
| Barry Margolin 2005-02-28, 8:50 pm |
| In article <1109640338.811910.277270@o13g2000cwo.googlegroups.com>,
dsingh2@stevens.edu wrote:
> Hello,
>
> I am facing a problem with execution of commands from within the shell
> script. The following is the trouble maker.
>
> The command when executed from the prompt behaves as follows when the
> host 'courage' is not available
>
> $ ping -c1 -w1 courage >/dev/null 2>&1 || echo courage is down
> courage is down
>
> Now assume that the same text is in a script variable
>
> EXEC_STR="ping -c1 -w1 courage >/dev/null 2>&1 || echo courage is down"
>
> and i execute it by
> exec $EXEC_STR or ` echo $EXEC_STR `
That should be:
eval $EXEC_STR
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| dsingh2@stevens.edu 2005-02-28, 8:50 pm |
| Thanks Barry.... now it works great 
|
|
|
|
|