4 ms·
>Ever tried to figure out if a bash variable is a string or an array? if [[ "$(declare -p some_array)" =~ ^declare -([^\ ]*a[^\ ]*)\ .* ]]; then
by 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".