Skip to content

Unexpected shellcheck parse error for code that runs correctly and looks correct #3475

Description

@xsdg

For bugs with existing features

Here's a snippet or screenshot that shows the problem:

#!/bin/sh
geeqie_exe="$1"
completions_file="$2"

# Make sure input files exist.                                                                                                                                                                
if [ \! \( -x "$geeqie_exe" -a -e "$completions_file" \) ]; then
    echo "Missing input files"
    exit 2
fi

Here's what shellcheck currently says:

In ./build-aux/test-bash-completions.sh line 15:
if [ \! \( -x "$geeqie_exe" -a -e "$completions_file" \) ]; then
^-- SC1009 (info): The mentioned syntax error was in this if expression.
   ^-- SC1073 (error): Couldn't parse this test expression. Fix to allow more checks.
         ^-- SC1072 (error): Expected comparison operator (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

For more information:
  https://www.shellcheck.net/wiki/SC1072 -- Expected comparison operator (don...
  https://www.shellcheck.net/wiki/SC1073 -- Couldn't parse this test expressi...
  https://www.shellcheck.net/wiki/SC1009 -- The mentioned syntax error was in...

Here's what I wanted or expected to see:

This code runs as expected, and seems to be trivially correct

$(export geeqie_exe="/bin/ls"; export completions_file="/etc/passwd"; [ \! \( -x "$geeqie_exe" -a -e "$completions_file" \) ] && echo failcase || echo bypass)
bypass

$(export geeqie_exe="/bin/noexist"; export completions_file="/etc/passwd"; [ \! \( -x "$geeqie_exe" -a -e "$completions_file" \) ] && echo failcase || echo bypass)
failcase

$(export geeqie_exe="/bin/ls"; export completions_file="/etc/noexist"; [ \! \( -x "$geeqie_exe" -a -e "$completions_file" \) ] && echo failcase || echo bypass)
failcase

$(export geeqie_exe="/bin/noexist"; export completions_file="/etc/noexist"; [ \! \( -x "$geeqie_exe" -a -e "$completions_file" \) ] && echo failcase || echo bypass)
failcase

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions