简体   繁体   中英

unix expr: syntax error

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 eg

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

Any suggestions?

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM