Re: Very Simple script driving me nuts!

joe_at_invalid.address
Date: 05/15/04


Date: Sat, 15 May 2004 19:14:00 GMT


"Trent Curry" <trentcurry@REM0VEhotmail.com> writes:

> I know I am missing something really trivial here. I've bene away
> from shell scripting over the years, for the most part been working
> with the likes of Perl, C++, and Java, and I seem to have forgotten
> some aspect of shell programming it seems thats biting me in the
> arse, when I wanted to write an utterly simple script to save me
> some time.
>
> sendcmd:
> 1 #!/bin/sh
> 2
> 3 CMD="./sendcommand blah 127.0.0.1 2701 '$*'"
> 4 echo -n "CMD: $*"
> 5 echo
> 6 $CMD
> 7 echo
>
> Say I run it like this, the echo looks fine
>
> $ ./sendcmd do this
> CMD: do this
>
> but sendcommand ask as if no params were passed. If I remove the ''
> around $* on line 3, then it works, but I need literal single quotes
> aroudn the params being pased, so to allow spaces. I wanted to use
> $* so I don't have type any surrounding quotes when I use my script,
> and have the script put singles around that. (Notice I didnt put any
> '' around "do this" on the command line.

Are you sure it's not sendcommand that's messing up? The script you
show works (more or less) as you seem to want it to with all shells
I've tried. For test purposes I changed it to

#!/bin/sh
CMD="echo blah 127.0.0.1 2701 '$*'"
echo -n "CMD: $*"
echo
$CMD
echo

Output:
CMD: do this
blah 127.0.0.1 2701 'do this'

With the sh on Solaris (which is a Bourne shell) echo -n doesn't work
as you want. You're probably better off using printf(1) if you have
it.

Joe

-- 
"Surprise me"
  - Yogi Berra when asked where he wanted to be buried.


Relevant Pages

  • SUMMARY: Annoying Shell/Terminal Problem
    ... that a startup script was set to trapINT. ... # echo howdy^Cecho doody ... The ^C canceled the first echo, but it doesn't cause the shell ... when I run those echo commands from the shell. ...
    (SunManagers)
  • Re: take file name from command line arguement and write to file
    ... the Bourne Again Shell. ... > echo $a ... splitting, parameter substitutions etc. ... script and first sees the eval command, at first it behaves the usual ...
    (comp.unix.shell)
  • Re: help regarding shell script to find out if a directory exists at a given path
    ... echo "found directory at the given path.." ... Every line I write is potentially a line in a script. ... resulting program will be easier to maintain than a bash script. ... shell is more than powerful enough. ...
    (comp.unix.programmer)
  • Re: Mutiple fork return status
    ... from a script you can obtain the exit code of any background process you spawned with the "wait" builtin, it will return the process' exit code as its own or 127 in case of errors try this sequence of commands, they are picked from memory but should be correct: ... # echo $? ... if you issue a "wait" while the process you are inquiring about is still running, the script will pause until the process in question exits by itself or is terminated. ... you can get more info about the "wait" builtin in the docs for the shell of your choice. ...
    (comp.os.linux.misc)
  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... > Practical flexibility vs real flexibility. ... > programs inside a shell, ... @echo off ... But for me it is essential, that the script ...
    (alt.lang.asm)

Loading