-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2299
Vidar Holen edited this page Aug 17, 2021
·
1 revision
path="/path/to/MyFile.mp3"
echo "Playing ${${path##*/}%.*}" # Expect: Playing MyFile
path="/path/to/MyFile.mp3"
tmp=${path##*/}
echo "Playing ${tmp%.*}"
ShellCheck found what appears to be a nested parameter expansion. In the example, it was hoping to combine ${var##*/}
to strip the directory and ${var%.*}
to strip the extension.
Parameter expansions can't be nested. Use temporary variables instead, so that each parameter expansion only does a single operation.
Alternatively, if the goal is to dynamically generate and expand a variable name, see SC2082.
None
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!