error while storing output in variable
Hi,
I am facing error while I try to store output in the variable in bash script. If i run the script without storing it to variable it runs fine. But if i try to store output in variable then it gives errors. [root@localhost ~]# for i in localhost ; do echo $i ; ssh $i "/usr/bin/lsb_release -a | /bin/grep Distributor | cut -f2 -d ":" | xargs " ; done localhost root@localhost's password: CentOS [root@localhost ~]# for i in localhost ; do echo $i ; ssh $i " ver=`/usr/bin/lsb_release -a | /bin/grep Distributor | cut -f2 -d ":" | xargs` ; echo $ver " ; done localhost root@localhost's password: LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch bash: line 1: Distributor: command not found bash: -c: line 2: syntax error near unexpected token `(' bash: -c: line 2: `Description: CentOS release 5.5 (Final)' Thanks, |
Quote:
Code:
ver=`/usr/bin/lsb_release -a | /bin/grep Distributor | cut -f2 -d ":" | xargs` So once invoke: Code:
~$ for i in localhost ; do echo $i ; ssh $i "echo $SHELL" ; done Code:
~$ for i in localhost ; do echo $i ; ssh $i " ver=$(/usr/bin/lsb_release -a | /bin/grep Distributor | cut -f2 -d ":" | xargs) ; echo $ver " ; done |
Thanks Shivaa, it worked . Can you please give me the logic/explaination of the command ver=$(/usr/bin/lsb_release -a | /bin/grep Distributor | cut -f2 -d ":" | xargs).
|
This is bash style variable declaration. It's recommended to use $(...) over backticks (see here).
Go through the link mentioned. It was a problem because your remote machine was not storing output of command in a variable (or it was not accepting backticks convention). Anyway, if it's solved, then mark the thread as solved. :) |
thanks Shivaa, I'll go through the link .
|
All times are GMT -5. The time now is 02:45 PM. |