Re: shellcheck, bashism's and one liners.
On Sun, Mar 17, 2024 at 09:25:10AM +0000, Tim Woodall wrote:
> Hi,
>
> I've been cleaning up some bash scripts
Good
> and, where possible, addressing things reported by shellcheck.
Oh, shellcheck, https://www.shellcheck.net/
> I have this one-liner (which works but shellcheck doesn't like the
> quoting)
>
> idxsrc="$( newest_file $( APT_CONFIG=${APT_CONFIG} apt-get indextargets --format '$(FILENAME)' 'Identifier: Packages' ))"
>
> SC2016: Expressions don't expand in single quotes, use double quotes for that.
> SC2046: Quote this to prevent word splitting.
>
> The first is easy enough to avoid by using backslash instead. But the
> second I can't see how to fix as a one-liner.
>
> I can make shellcheck happy by doing it like this:
>
> mapfile -t idxpackages < <( APT_CONFIG=${APT_CONFIG} apt-get indextargets --format \$\(FILENAME\) 'Identifier: Packages' )
> idxsrc="$( newest_file "${idxpackages[@]}")"
For what it is worth:
- a shell is nice and good tool
- shellcheck is an afterthought
- my shellcheck experience learnt me that it can't see the difference
between "dangerous" and "potentionally dangerous"
Thing I'm trying to tell: Avoid that shellcheck blocks you
Groeten
Geert Stappers
--
Silence is hard to parse
Reply to: