Reputation: 3303
I am trying a FOR loop in Linux Shell script to generate a condition to be passed on to a SQL query within the shell script. The following is the portion that is giving error:
> condition=${primarykey//,/ }
> echo $condition
cond1 cond2
> temp=""
> for i in $condition
> do
> $temp="${temp}c.${i}\=s.${i} AND "
> done
I am looking for the following expression to be generated:
> echo $temp
c.cond1=s.cond1 AND c.cond2=s.cond2
However, I get the following error:
./script.sh: line 28: =c.cond1\=s.cond1 AND : command not found
./script.sh: line 28: =c.cond2\=s.cond2 AND : command not found
Could someone help me with the right way to get this expression?
Upvotes: 0
Views: 47
Reputation: 78
This would do it.
temp=""
for i in $condition
do
temp="$temp c.$i=s.$i AND "
done
Upvotes: 1
Reputation: 799200
The $
implies substitution. As in, take the contents of the variable and substitute it into the command line at that point. If you want to assign then you must not substitute.
TL;DR: Remove the dollar sign to the left of the equals sign.
Upvotes: 1