There are several problems here. The direct answer to your question is bash
doesn't allow spaces around the assignment operator.
# BAD
foo = bar
# GOOD
foo=bar
But I need to continue: the for
line doesn't do what you want. The backticks will expand the output and split by whitespace, so you end up with for i in node1 john node2 snow node3 aya node4 stack
, which gives you eight iterations with $i
being one word, not four iterations with $i
being one line. If you want to iterate over lines, use read
.
Also, there can't be any spaces inside the value of an assignment, unless the value is quoted. If you write host=awk '{print $1}' $i
, it will make host
have the value awk
, then launch a subshell and try to run the program {print $1}
with the parameter that is the value of i
- not what you meant. But you actually probably meant that you want to run awk
, and here you'd use the backtick quotes, or even better $(...)
because it allows nesting and is clearer to read.