Reputation: 713
I don't know if you can help me... I have a problem with the following code:
#!/bin/bash
if [ $# = 0 ]; then
awk '{for (x=5; x<=NF; x++) {printf "%s ", $x } printf "\n" }' affy.txt
else
columns=""
for i in $@; do
if [ $i = "-g" ]; then
word=$2
is_there_g="True"
break
else
is_there_g="False"
fi
columns+="$i,"
shift
done
columns=${columns%,}
if [ $is_there_g="False" ]; then
cat affy.txt | cut -d" " -f$columns
else
grep $word affy.txt | cut -d" " -f$columns
fi
fi
echo $is_there_g
So, there's a problem obtaining the results I want. It's about the last If/else written.
When $is_there_g="False"
, I wanna do this: "cat affy.txt | cut -d" " -f$columns"
.
And if it's True
, then: "grep $word affy.txt | cut -d" " -f$columns"
.
I assess it using "echo $is_there_g"
at the end of my code .
So the problem is that the results I obtain are always for a False case even though "echo $is_there_g" gives me a True value
. Why???
Upvotes: 0
Views: 1582
Reputation: 225032
You need spaces around the operator:
if [ $is_there_g = "False" ]; then
man bash
or man test
for more information.
Upvotes: 3