top | item 35986296

(no title)

cwingrav | 2 years ago

Also, use shellcheck. Incorporate it into you editor. Fix all warning and don’t ignore them. This will push you deep into bash syntax rabbit holes but you come out better the other side.

discuss

order

cwingrav|2 years ago

A lot of bash errors are not understanding possible cases due to white space.. which shellcheck catches. After using it for a while, I don’t even really worry about white space because of the good habits I’ve learned/(been forced to use).

ndsipa_pomu|2 years ago

That's all well and good until you come across a filename with a linefeed in it - null termination is where it's at!

(I can't actually recall encountering a filename that includes a linefeed)

blueflow|2 years ago

Find the problem:

  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.

xorcist|2 years ago

The style issue shellcheck reports here is probably what we both suspect it is.

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.

rascul|2 years ago

I would probably do it this way:

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.

ndsipa_pomu|2 years ago

Using "echo" at all is a problem. It's recommended to switch to "printf" instead as echo has unfixable problems, especially with strings that start with a dash.

  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/null

saagarjha|2 years ago

…what’s the problem?