3 ms·
Scripts? What happened to scripts?
by Grimeton 2y ago
Scripts? What happened to scripts?
- candiddevmike 2y agoAuthor here, the blog post addresses this: > To wrangle these beasts, we’ve all resorted to wrapping commands in shell scripts or aliases—the infamous “bash spaghetti.” This approach may solve the repeatability problem, but it introduces new ones: > Argument Wrestling: Ever tried to figure out if a bash variable is a string or an array? Or when to quote something with spaces? It’s a battle. > Discoverability Disaster: Your beautifully crafted CLI tool is now hidden behind an unsightly bash script. Not the most welcoming first impression.
- Grimeton 2y ago>Ever tried to figure out if a bash variable is a string or an array? if [[ "$(declare -p some_array)" =~ ^declare -([^\ ]*a[^\ ]*)\ .* ]]; then echo "Array". fi This is the quick and dirty version and it doesn't recognize an array that was assigned to a nameref, but that's a different discussion. >Or when to quote something with spaces? It’s a battle. You __ALWAYS__ quote and if you want to be on the safe side you always use "{}" around the variables as well. You also use "set -o nounset" to do yourself the favor of not working with variables that don't exist because of e.g. typos. >Discoverability Disaster: Your beautifully crafted CLI tool is now hidden behind an unsightly bash script. Not the most welcoming first impression. How's that different from the macro? The attempt is the same, to abstract the complex command line options of a tool behind something "easier".