by cwingrav · 3y ago · 0 comments
(I can't actually recall encountering a filename that includes a linefeed)
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.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.
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.
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.
Is Bash just surviving because no one knows about it or has remembers it while its been hiding in your system for 20 years?