4
Maxeh
2y

Why the fuck is it so hard to write a simple bash script. Syntax so strange and so many symbols you need to know. If you need to do calculations with floating point numbers, the mess is perfect.

Comments
  • 0
    I don't think bash has floating point math, does it? I always use bc for that.

    If you think bash has so many symbols, try perl! 😁

    btw, bash ftw! :)
  • 0
    @netikras Nope, integers only.
  • 0
    I used awk for that and also got confused with comparing numbers with <, > instead of - lt and - gt. Some stuff is not so intuitive.
  • 2
    Agreed, it can be such a mess...
  • 2
    For whatever your purpose is, I'll give this quote:

    "Don't hammer a screw in" - probably somewhere on the internet

    In other words, pick the right tool for the job
  • 2
    @EngineerCoding I use bash/makefike often for small scripts, but even if statements or small loops seem so verbose and complicated compares to other languages
  • 1
    Lol I agree completely. It’s the one language that I ended up giving up on a couple days after trying to learn it saying that I would come back to it another time. If statements are confusing knowing when to use single or double brackets or to add a semicolon. Having to use -gt for greater than instead of >. Knowing how certain terminal commands work when scripting against them. Using numbers is confusing as well as I believe you have to store them in different types of variables depending on other random shit.

    There’s just so much random tiny pieces of information that can mess everything up. However, it’s an extremely powerful scripting language and I would love to learn it. It’s just such a pain in the ass.
  • 1
    Perhaps Fish or python are an option
  • 0
    That's the reason a lot of people use Perl or Python for their more complicated system scripts.
  • 0
    @MrCush It's not as bad as you describe it. In fact, some of the things you're saying aren't really specific to Bash or have nothing to do with it.

    If you're only targeting Bash and you don't need your scripts to be 100% compatible with other shells, it's really way easier to grasp. If I may, let me give you a couple of pointers about the examples you used:

    About knowing when to use single brackets or double brackets, just *always* use double brackets. The difference between the two is that the single bracket is actually a command, while the double bracket is a Bash expression. The double bracket is way more flexible and less prone to errors.

    About using -gt or >, it's easier if you think about it like this: all variables in Bash are strings; Bash can do numeric comparisons using -gt inside double brackets, but it's clearer if you use Bash's arithmetic expression syntax for all things numeric:

    if [[ "$something" == "something" ]]

    if (( variable > 0 )) # No need for $ inside those
  • 0
    @MrCush I hit the character limit in my previous comment.

    Just a final notice about a good resource for learning Bash's scripting language: the Bash Hackers Wiki.

    https://wiki-dev.bash-hackers.org/s...

    Special attention should be paid to both the “Beginner Mistakes” and the “Obsolete and deprecated syntax” pages for great justice:

    https://wiki-dev.bash-hackers.org/s...
    https://wiki-dev.bash-hackers.org/s...
Add Comment