Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not check for unescaped parenthesēs in certain contexts #2906

Open
2 tasks done
mirabilos opened this issue Jan 20, 2024 · 0 comments
Open
2 tasks done

does not check for unescaped parenthesēs in certain contexts #2906

mirabilos opened this issue Jan 20, 2024 · 0 comments

Comments

@mirabilos
Copy link

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

#!/bin/sh
line=x
  if [ "${line##*AC_CONFIG_AUX_DIR}" != "$line" ]; then
    dirprefix="${line##*([}"
    dirprefix="${dirprefix%%])*}"
    mkdir -p "${dirprefix}"
  fi

source

Here's what shellcheck currently says:

No issues detected!

Here's what I wanted or expected to see:

A warning about failure to quote the two parenthesēs with a backslash each:

    dirprefix="${line##*\([}"
    dirprefix="${dirprefix%%]\)*}"

This is mandatory because POSIX allows implementations to extend pattern matching in these situations (C.2.14.1 in the current Issue 8 draft specifically mentions the Korn shell extglob extension of *(…) in pattern matching).

Unfortunately, both GNU bash and dash allow this (and so mksh’s lksh binary on Debian when in sh mode does), so this mistake is very widespread. It would be good for shellcheck to flag this as error.

Thanks @lanodan for noting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant