Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
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! :)
Maxeh8262yI used awk for that and also got confused with comparing numbers with <, > instead of - lt and - gt. Some stuff is not so intuitive.
Agreed, it can be such a mess...
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
MrCush1302yLol 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.
Perhaps Fish or python are an option
That's the reason a lot of people use Perl or Python for their more complicated system scripts.
@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
@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.
Special attention should be paid to both the “Beginner Mistakes” and the “Obsolete and deprecated syntax” pages for great justice: