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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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