getListing () {
if [ "$1" = ""];
then
alcListDir ~/Projects/Haskell/ -f \
| alcSortPath time | tac | xargs -n1 basename
else
alcListDir ~/Projects/Haskell/"$1"/ -f \
| alcSortPath time | tac | xargs -n1 basename | sed -e "s/^/"$1"\//"
fi
}
The above is giving me an error (when run with set -x) of:
+./rofi.sh:29> getListing ''
+getListing:1> [ '' '=' ']'
getListing:1: parse error: condition expected:
I'm invoking the function like so: getListing ""
What is the cause of the error?
""and]. That statement is also better written asif [ -z "$1" ]. And thesedcall leaves$1unquoted. Don't break out of the double quotes for$1there. – Kusalananda Mar 23 '19 at 18:09""]results in the final]that[wants, it thinks you tried to use a two-argument expression (not counting the]). The first arg should then be a condition and the second the operand to that condition. All conditions start with a dash, so anything else gives "condition expected". It's just hard to read here since there first arg is the empty string.[ foo = ]would givezsh:1: parse error: condition expected: foowhich at least shows where it expected the condition to be. – ilkkachu Mar 23 '19 at 18:58