-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2298
Vidar Holen edited this page Aug 17, 2021
·
2 revisions
(or ${${x}}
is invalid)
# Expecting $RETRIES or 3 if unset
retries=${$RETRIES:-3}
or
mypath="/tmp/foo.txt"
var=mypath
result=${$var##*/} # Expecting ${mypath##*/}, i.e. 'foo.txt'
retries=${RETRIES:-3}
or
mypath="/tmp/foo.txt"
var=mypath
result=${!var}
result=${result##*/}
ShellCheck found a parameter expansion ${..}
where the first element was a second parameter expansion, either ${$x..}
or ${${x}..}
. This is not valid.
In the first example, the extra $
was unintentional and should simply be deleted.
In the second example, ${$var##*/}
was used in the hopes that it would expand to ${myvar##*/}
and subsequently strip the path. This is not possible, and var
must instead be expanded indirectly in a separate step, before the path can be stripped as usual. More information and other approaches can be found in the description of SC2082.
None
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!