1. 10
  1.  

  2. 1

    It doesn’t really need to fork/exec a sub shell, {} would do instead of ().

    1. 1

      There were many code listings, please tell me which one You are addressing :)

    2. 1

      Can I get some remedial explanation for this line to convert hex to decimal:

      SIZE=$( printf “%d\n” 0x${SIZE} )

      Why add the newline to the format?

      Shouldn’t we quote “0x${SIZE}”? I guess it works for me in without it, but it makes me nervous for some reason.

      1. 3

        Newline or not does not matter, as it is automatically stripped anyway.

        0x${SIZE} without quotes is safe if you know it does not contain glob (like *) or IFS characters (like spaces, usually). In this case, we know it does not contain IFS characters (as the read command splits on IFS), and we can be relatively certain it won’t ever contain a glob character.

        Still not best practice, though, as we ultimately do not control the value ourselves.

        1. 2

          You are right the ‘\n’ newline is not needed there, but does not hurt as it seams.

          As for the quoting - its always a good idea to quote variable - which I sometimes forgot - but in that case the size is without spaces so it works without a problem.

          Regards.

          1. 3

            I can add that printf '%s\n' is such a common pattern that it is probably a good idea to include the newline even when it is unnecessary, because it is necessary when piping the result, which is what is usually done:

            printf '%s\n' "$x" | ...