I have a few lines code.
I just want to check if argument $1
is in the file with a while
loop so I write this code.
#!/bin/bash
if [ ! -z $1 ]
then
update=$1;
while read line
do
if [ $update == $line ]
then
echo "yes";
fi
done<./available_updates
fi
But in debugging if I run
[root@pc bagheri]# bash -x ./test.sh my_value
it says:
+ '[' my_value == 'my_value' ']'
and jump over that condition just because of these two single quotes and not printing the 'yes' word, but I am 100% sure that the my_value
is existed in available_updates
file. What should I do for that?
"$update" == "$line"
, because if you don't$line
can expand into multiple strings instead of one. – SparedWhisle Jul 19 '20 at 12:54$update
and$line
contain onlymy_value
, theset -x
output from the shell will not quote it. Above, you say that the output has no quotes around the firstmy_value
but there are quotes around the second. Is that right? Are you sure that's the exact output? Because the presence of quotes there indicates the value has some special characters, other than letters and the underscore, but your output doesn't show them. Please [edit] to clarify. – ilkkachu Jul 19 '20 at 18:26available_updates
to just one line which triggers the problem and add the output ofod -t c -t x1 available_updates
to your question. – Hauke Laging Jul 22 '20 at 02:12