0
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?

  • 4
    Typo: No space between "" and ]. That statement is also better written as if [ -z "$1" ]. And the sed call leaves $1 unquoted. Don't break out of the double quotes for $1 there. – Kusalananda Mar 23 '19 at 18:09
  • The funny thing here is the error message, "condition expected". What I suppose happens is that since ""] 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 give zsh:1: parse error: condition expected: foo which at least shows where it expected the condition to be. – ilkkachu Mar 23 '19 at 18:58

0 Answers0