▲ | deathanatos 2 days ago | ||||||||||||||||||||||
Or just don't use Bash. Python is a great scripting language, and won't blow your foot off if you try to iterate through an array. Other than that, yeah, if you must use bash, set -eu -o pipefail; the IFS is new and mildly interesting idea to me. > The idea is that if a reference is made at runtime to an undefined variable, bash has a syntax for declaring a default value, using the ":-" operator: Just note that defaulting an undefined variable to a value (let's use a default value of "fallback") for these examples is,
The syntax,
means "use 'fallback' if foo is unset or is equal to "". (The :, specifically triggers this; there's a bunch of others, like +, which is "use alternate value", or, you'll get the value if the parameter is defined, nothing otherwise.
And similarly,
will emit triggered if foo is set and not empty.)See "Parameter Expansion" in the manual. I hate this syntax, but it is the syntax one must use to check for undefined-ness. | |||||||||||||||||||||||
▲ | xelxebar 2 days ago | parent [-] | ||||||||||||||||||||||
Permit me to vent just a bit: > Python is a great scripting language, and won't blow your foot off if you try to iterate through an array. I kind of hate that every time the topic of shell scripting comes up, we get a troop of comments touting this mindless nonsense. Python has footguns, too. Heck, it's absolutely terrible and hacky if you try to do concatenative programming with it. Does that mean it should never be used? Instead of bashing the language, why not learn bash the language? IME, most of the industry has just absorbed shell programming haphazardly through osmosis, and almost always tries to shove the square pegs of OOP and FP into the round hole that is bash. No wonder people are having a bad time. In contrast, a data-first design that heavily normalizes data into line-oriented tables and passes information around in pipes results in simple, direct code IME. Stop trying to use arrays and embrace data normalization and text. Also, a lot of pain comes from simply not learning the facilities, e.g. the set builtin obviates most uses of string munging and exec:
Anyway, the senseless bash hate is somewhat of a pet peeve of mine. Exunt. | |||||||||||||||||||||||
|