D
D
DimiDr0lik2017-04-25 10:55:15
linux
DimiDr0lik, 2017-04-25 10:55:15

Why is the bash condition not checked?

Please tell me why in each of the conditions, the second part of the condition, the check passes as true?
It is necessary that the condition be executed once before the state of the stat value changes, what is my mistake?

#!/bin/bash
val="true"
while [ "1" -ne "0" ]
do
#stat=`iwinfo wlan0 assoclist | grep -o B0:E2:35:C5:F5:0A`
stat="dsfsdf"
if ; then
echo $val
val=false
echo 1
echo $stat
echo $val
elif ([ -z "$stat" ] && ); then
val="true"
echo 2
echo $stat
echo $val
fi
sleep 5
done
exit

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DimiDr0lik, 2017-04-25
@DimiDr0lik

I figured it out using the article https://habrahabr.ru/post/47706/

#!/bin/bash
val=true
while true
do
#stat=`iwinfo wlan0 assoclist | grep -o B0:E2:35:C5:F5:0A`
stat="dsfsdf"
if [ -n "$stat" -a true = "$val" ]; then
echo $val
val=false
echo $stat
echo $val
elif [ -z "$stat" -a false = "$val" ]; then
val="true"
echo $stat
echo $val
fi
sleep 5
done
exit

S
Saboteur, 2017-04-25
@saboteur_kiev

); then
"-eq" is for numeric comparisons only. Strings are compared by = , but it's better to write ==

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question