Skip to content

Files

Latest commit

 

History

History
30 lines (19 loc) · 818 Bytes

SC2299.md

File metadata and controls

30 lines (19 loc) · 818 Bytes

Pattern: Use of nested parameter expansion

Issue: -

Description

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.

Example of incorrect code:

path="/path/to/MyFile.mp3"
echo "Playing ${${path##*/}%.*}"    # Expect: Playing MyFile

The extra $ was unintentional and should simply be deleted.

Example of correct code:

path="/path/to/MyFile.mp3"
tmp=${path##*/}
echo "Playing ${tmp%.*}"

Further Reading