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

[SC2116] exception: $(echo ...) used to compose regular expression patterns #1746

Open
2 tasks done
64kramsystem opened this issue Nov 5, 2019 · 0 comments
Open
2 tasks done

Comments

@64kramsystem
Copy link

For new checks and feature suggestions

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

#!/bin/bash

[[ 123 =~ $(echo '^123\b') ]] && echo match

Here's what shellcheck currently says:

Line 3:
[[ 123 =~ $(echo '^123\b') ]] && echo match
          ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.

Here's what I wanted or expected to see:

No warnings.

Since non-trivial regular expressions (to be matched with the =~ operator) can't be written inline, one needs a workaround, typically $(echo <expression>), which ideally should not raise a warning.

I'm also a bit perplexed about Shellcheck recognizing the =~ operator as a command, which causes the warning to be raises (however, I'm not familiar with the internals).

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