unix expr: syntax error

724 views Asked by At

Why is the following expression giving me a expr: syntax error?

pingval=`expr ping6 -c 1 "$url"`

Basically I want to use the value returned by the above expression in another expression e.g.

var=$($pingval|tail -1 ....

Any suggestions?

1

There are 1 answers

9
declension On

Why are you using expr at all? It's generally used for simple maths / string functions.

You can assign the result (stdout) of that expression just using the backticks, or in a more modern way directly with:

pingval=$(ping6 -c1 "$url" | tail -1)

If you did want to build the shell expression before using, try something like:

cmd="ping6 -c 1 '$url' | tail -1"
echo cmd | sh