echo "$(tr -dc A-Za-z0-9 </dev/urandom | dd count=1 bs=16 2>/dev/null)"
^-- SC2005 (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
I have experienced so many situations where shellcheck is giving harmful advice or warns me about the thing that is exactly my intention. printf "%s\n" "$(tr -dc A-Za-z0-9 </dev/urandom | dd count=1 bs=16 2>/dev/null)"
If you don't require the line feed, then you can just use: tr -dc A-Za-z0-9 </dev/urandom | dd count=1 bs=16 2>/dev/nullAnd i do require the line feed. Following shellcheck's advice broke the code.
Just tested it and ShellCheck is happy with the printf version:
printf "%s\n" "$(tr -dc A-Za-z0-9 </dev/urandom | dd count=1 bs=16 2>/dev/null)"
It's also got a stylistic improvement (in my opinion, anyhow) in that the line feed is explicit in the printf command rather than being almost a side effect of echo.Edit: I see your point about the "tr" not enabling a dash, so my example falls a bit flat, but my point stands in other scenarios. It's good practise to avoid echo where feasible. I think the double quotes will also protect in this instance. The problem with relying on the tr string to not foul up echo is that you may later adapt the code and use a different translate string which could then introduce a tricky bug to track down.
# shellcheck disable=SC2005
tr -dc A-Za-z0-9 </dev/urandom | dd count=1 bs=16 2>/dev/null; echo
A few less characters to type, you get your newline, and shellcheck doesn't complain.
The call to echo has a likely purpose is to trim some spaces from a string, but it's not at all obvious why this is done or what the benefit is. In the best case, it leaves the reader pondering this weird semi-no-op.
If you think shellcheck, and probably most readers, is wrong in this assertion, just speak your mind and let's learn from one another. But I certainly can't guess your intention here.
(I can't actually recall encountering a filename that includes a linefeed)
Is Bash just surviving because no one knows about it or has remembers it while its been hiding in your system for 20 years?