Bash code to print all folders:
for f in ~/*;
do
if [ $f == '/home/sk/.' -o $f == '/home/sk/..' ]; then
true
else
echo "$f"
fi
done
It works on bash. When i ran the code on z shell, it threw error:
= not found
Then I converted [
into [[
, ]
into ]]
to avoid this error in z shell and ran it on z shell. It threw next error:
condition expected: $f
With [[
and ]]
, bash also throws error as:
syntax error in conditional expression
syntax error near `-o'
Is there a POSIX standard to do string comparison in shell, that works across shells?
case
which supports an arbitrary number of shell patterns applied against a string and arbitrary associated shell commands you might apply when a match is true. – mikeserv Jun 08 '15 at 08:15