PDA

View Full Version : unary operator expected



kikosanjuan
November 22nd, 2017, 04:40 PM
#!/bin/bash


for WFILE in $(sudo ls -lR / | grep .sh);
do
if [ -l "$WFILE" ];
then
echo '$WFILE' Is a Directory
else
if [ -d "$WFILE" ];
then
echo "$WFILE" is a link
fi
fi
done

error: line 5: unary operator expected

what diud I wrong?

greetings
kikosanjuan

howefield
November 22nd, 2017, 04:42 PM
Thread moved to the "Programming Talk" forum.

spjackson
November 23rd, 2017, 09:46 AM
Welcome to the forums.

There is no operator -l that tests whether a file is a plain file, which is why you get the syntax error. You probably want to use -f instead.

I am assuming that this is a learning exercise, so I won't go into detail about several other issues with this script.