Reputation: 1300
I have a following case where I want to execute if/elif/else bash conditional statement in one line over each loop.
for file in *; do
if[ ! -d "$file" ]; then
continue;
elif[ -f "$file" ]; then
echo "$file";
else
exit 1
fi
done
I tried to write it in one line:
for file in *; do if[ ! -d "$file" ]; then continue; elif [ -f "$file" ]; then echo "$file"; else exit 1; fi; done
but it is giving unexpected syntax error: 'then'
error
Where am I getting it wrong?
Upvotes: 0
Views: 44