Sample Header Ad - 728x90

String comparison in single brackets in zsh

31 votes
3 answers
42668 views
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?
Asked by user93868
Jun 7, 2015, 02:23 PM
Last activity: Nov 5, 2023, 11:12 AM