Paulius Mickus Paulius Mickus - 2 years ago 71
Bash Question

shell script works but drop error "line[8] expected argument ["

I have shell script that works (does what i want to do,finds if listed user is online), but each time drop error "line[8] expected argument [". I've tried using == but same thing. There's my code:

until [ $truth -eq 1 ]

for i; do
isthere=$(who is here | awk '{print $1}' | grep $i)
if [ $isthere = $i ] #(8 line is here)
echo "found user: "$isthere". program now will close.";
exit 0;
echo "user not found, retrying after 3sec...";
sleep 3;

Thank you for you help and time.

Answer Source

Looks like $isthere or $i is empty. You should quote them: if [ "$isthere" = "$i" ]

In other news: most semicolons are useless; a semicolon it is not a statement terminator, but a statement separator, along with newline.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download