[plug] script problem
Russell Steicke
russells at plug.linux.org.au
Sat Aug 17 18:50:36 WST 2002
On Sat, Aug 17, 2002 at 06:13:44PM +0800, Jon Miller wrote:
>
> I'm trying to get this line to work in a bash shell script and I'm getting
> an error stating that -c command not found.
>
> snip of script
> # first ping a name server and get results
> var_res=ping -c 5 139.130.4.5 | grep icmp_seq=4 | awk '{ print $5 }'
Here you're setting the variable "var_res" to the value "ping", then
trying to execute the command "-c". This is obviously not what you really
want.
What do you want to do with var_res? If it's a command to execute later,
you need to quote it's value, probably with "" since you have embedded
single quotes in the string. If you want var_res to have the value of the
output of the command, then surround ping... with `` or $( ). You note
that these give you different errors, could you post these other errors?
The code works on my machine in both cases, "" and ``.
> #
> I've tried using " " around the command and also ` ` but these produce a
> different error.
>
> Is there a better way of issuing the command and getting the result in the
> variable?
Yes, with
var_res=$(ping ...)
$() nests properly (` ` is hard to nest), so it's a good way to go.
More information about the plug
mailing list