Skip to content

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

Description

@xsdg

For bugs with existing features

  • Rule Id (if any, e.g. SC1000): SC1009, SC1072, SC1073
  • My shellcheck version (shellcheck --version or "online"): version: 0.11.0
  • The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
  • I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit

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