-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
For new checks and feature suggestions
- https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
- I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
base="[hello] [world]"
pref="[hello]
suff="[world]"
pref="${base%$suff}"
# sets to $base, not "hello ", because $base doesn't end in any of the characters d,l,o,r,wHere's what shellcheck currently says:
Nothing
Here's what I wanted or expected to see:
Warning: the substring removal expansion accepts a pattern, not a literal string.
Use slicing operators instead:
"${base%suff}" -> "${base:0:${#base}-${#suff}}"
"${base#pref}" -> "${base:${#pref}}"
(note: this advice isn't perfect for suffixes, since if the "suffix" is longer than the base, this will silently remove len(suff)-len(base) characters from the end of $base)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels