Why is echo showing the command and not the output of the command once I start using it in a FOR I loop? For example this command works
root@linux1 tmp]# iscsiadm -m node |awk '{print $1}' 192.168.100.88:326
But not in a FOR I loop
[root@linux1 tmp]# for i in 'iscsiadm -m node | awk '{print $1}'';do echo $i;done iscsiadm -m node | awk {print }
I want the command to print the first field so then I can add other functionality to the For I loop. Thanks
EDIT — Not sure why I got voted down on this question. Please advise.
Advertisement
Answer
You’re not executing the iscsiadm
and awk
commands, because you quoted it; that makes it a literal string. To substitute the output of a command back into the command line, use $(...)
for i in $(iscsiadm -m node |awk '{print $1}'); do echo $i done