Skip to content

Files

Latest commit

 

History

History
26 lines (16 loc) · 921 Bytes

SC2300.md

File metadata and controls

26 lines (16 loc) · 921 Bytes

Pattern: Parameter expansion starts with command substitution

Issue: -

Description

ShellCheck found a parameter expansion that begins with a command substitution, such as $(..) or `..`. This is not valid. Parameter expansion only works on variables (normal or special).

In the example, the user hoped to apply the construct ${var##*/}, stripping the path, to the current git root directory as output by git rev-parse --show-toplevel. Since parameter expansion only works on variable, the command substitution must be assigned to a variable first like in the correct example.

Example of incorrect code:

echo "Building ${$(git rev-parse --show-toplevel)##*/}"

Example of correct code:

tmp=$(git rev-parse --show-toplevel)
echo "Building ${tmp##*/}"

Further Reading