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
Post a Comment