2
Jedidja
2y

ugh what have I done to myself?

Today I started this codingame thing someone mentioned on here, but because I'm stubborn I've played every puzzle or game in bash so far...
So yeah, I'm loosing to all the cool kids using C++ or python even on simple stuff and I'm always struggling with this weird syntax - like "$" or not ... whitespace? parenthesis?

I mean I do like some bash but these games are really not made for it

Comments
  • 2
    There is a small, but very important difference between $var and ${var} if you mean that in your rant.

    I recommend always using ${var} because it _is_ the correct form that has no room for misinterpretation.

    Simplest example is variable expansion:

    file_prefix="test"
    file_uuid=$(uuidgen)
    file_extension="txt"

    file_name="$file_prefix_$file_uuid.$file_extension"

    file_name will be evaluated wrong. Because the variables will not be correctly parsed.

    '$file_prefix_' is the variable name in the string (underscore at end).

    file_name="${file_prefix}_${file_uuid}.${file_extension}"

    Will be always correct.
  • 0
    @IntrusionCM ok thanks!
    There's so much weird stuff in bash that maybe I should start actually learning it instead of just trying to get stuff working
  • 0
    @IntrusionCM I also had some fun run ins with missing spaces. and with to much spaces
  • 0
    @Jedidja Yes, no... Maybe?

    Bash done right can be beautiful, but requires commands like JQ or BC (bash calculator) as simple bash even lacks floating point arithmetics.

    Never the less it's interesting how much you can achieve in a scripting language that 's limited and quirky as bash.

    Most of all bash taught me to hate CLIs with wrong exit codes and -/ or improper usage of stdout vs stderr.
Add Comment