bash - How do I pipe in command run using backtick? -


i have bash command,

a=`xyz | head -n 1 | awk '{print $2}'` 

which used version number

i using number of times, avoid redundancy, decided store string , execute whenever need, stdout of xyz getting stored variable.

this how i'm doing it,

cmd="xyz | head -n 1 | awk '{print \$2}'" a=`$cmd` 

what doing wrong? how fix it? suggest if there simpler/better way of achieving it.

suggest if there simpler/better way of achieving it.

you command can shortened to:

xyz | awk '{print $2; exit}' 

and can create function rather storing in string:

mycmd() {     xyz | awk '{print $2; exit}' } 

and use as:

a=$(mycmd) 

Comments

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

collision detection - C++ library for mesh to mesh intersection: what is available? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -