Paulius Mickus Paulius Mickus - 7 months ago 26
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:

#!/bin/sh
truth=0;
until [ $truth -eq 1 ]
do

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


Thank you for you help and time.

Answer

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.