Earlier quoted context omitted.
Same. Shell and glue-scripts in Python. The activation energy required is now close to zero.
I hope I never have to be the one to read those scripts.
Pure Sh Bible
71–80 of 138 posts
Re: Pure Sh Bible
#72 - repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
- id: shellcheck
args: [-e, SC2154, -e, SC1091, -e, SC1090]
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.6.0-2
hooks:
- id: shfmt # requires Go to build
args: [-i, '4', -ci, -sr, -w, -s]Re: Pure Sh Bible
#73Mildly annoyed when people constantly refer to their article as the Bible of X. For those of us who are religious, it is in poor taste.
It may be in poor taste, but from a religious person’s point of view, quite a bit of the current culture in most western nations is in quite poor taste. I understand and sympathize with your objection, but I think that those called to faith (including myself) need to make peace with secularization and do as we are taught: take the road of peace at all times, accept without condoning, approach all things with open han…
That's the way I always viewed it anyway, but I'm also not religious, so who am I to say how you view things, right? But just a thought...
Re: Pure Sh Bible
#74What is everyone's current favorite one-liner for replacing a string in all files that match? In other words alternative implementations of this: ruby -pi -e "gsub(/Net::HTTPServerException/, 'Net::HTTPClientException')" {lib,knife}/**/*.rb
Re: Pure Sh Bible
#75I have to take exception to some of this; it's "technically correct" but like much of shell, likely full of terrifying edge cases that are best avoided. For instance, using eval to have variables with variable names is madness. $ var="world" $ eval "hello_$var=value" $ eval printf '%s\n' "\$hello_$var" I suppose the fancy business with printf is flexing, but I suspect the majority of people scanning documents like th…
It's well worth learning to use printf instead of echo to avoid all the various ways that echo can break or is not well defined. https://mywiki.wooledge.org/BashPitfalls#echo_.24foo
Re: Pure Sh Bible
#76If you are at this level of required complexity as in those examples, you should use a proper programming language, not shell. Half those snippets fail with spaces in the wrong place, newlines, control characters, etc. I think all such shell "magic" should come with a huge disclaimer pointing the user at better alternatives such as perl or python. And all snippets should have the necessary caveats on horribly broken…
I enjoy using bash, and throw together little scripts now and then. It is convenient to be able to wrap up some bash commands and turn them into a script, when I realize I’ve been using them repeatedly. But, every time I see examples of how to write sh scripts properly, it makes me wonder if this is just the wrong way to look at the world. Maybe it would be easier to extend Python down to make it better for command l…
Re: Pure Sh Bible
#77I have to take exception to some of this; it's "technically correct" but like much of shell, likely full of terrifying edge cases that are best avoided. For instance, using eval to have variables with variable names is madness. $ var="world" $ eval "hello_$var=value" $ eval printf '%s\n' "\$hello_$var" I suppose the fancy business with printf is flexing, but I suspect the majority of people scanning documents like th…
Here's a common pattern for appending to PATH system-wide once:
# /etc/profile.d/foo.sh
DIR=/opt/foo/bin
case ":$PATH:" in
*":$DIR:"*) ;;
*) PATH="$PATH:$DIR"; export PATH ;;
esac
unset DIR
If zsh or bash is available: # $1 var
# $2 prepend this string to var
# $3 separator (: default if omitted)
# doesn't remove or prevent duplicates
prepend() {
eval "export $1=$2\${$1:+${3-:}\$$1}"
}
# $1 var
# $2 append this string to var
# $3 separator (: default if omitted)
# doesn't remove or prevent duplicates
append() {
eval "export $1=\${$1:+\$$1${3-:}}$2"
}Re: Pure Sh Bible
#78I have to take exception to some of this; it's "technically correct" but like much of shell, likely full of terrifying edge cases that are best avoided. For instance, using eval to have variables with variable names is madness. $ var="world" $ eval "hello_$var=value" $ eval printf '%s\n' "\$hello_$var" I suppose the fancy business with printf is flexing, but I suspect the majority of people scanning documents like th…
var=world
declare -n tmp="hello_$var"
tmp=value
printf '%s\n' "$hello_world" # value
I highly recommend this pattern if you want to emulate jagged 2d arrays or other nested data structures in bash for some reason.Re: Pure Sh Bible
#79Earlier quoted context omitted.
It shouldn't. "Bible" etymologically derives from "book", and its meaning denotes an authoritative book, or "the" book on a topic. While it is true that the "Christian Bible" has customarily been shortened to just "Bible", in principle it is appropriate to call any authoritative book that claims to be "the" book on a topic as a "Bible", without necessarily carrying any religious connotations. That's not to say that p…
The common phrasing christians use is actually "The Holy Bible", with "Holy" being a common word in the bible meaning "set apart for God". So "The Holy Bible" is that particular "Bible" (book) which has been set apart for God. In fact, calling it a Holy Bible implies there are Bibles which are not Holy. As one would expect, given a bible is just a book, in greek.
Re: Pure Sh Bible
#80"Ternary Tests"
Can anyone point to where in the POSIX standard ternary test are described. (NB. Pure POSIX sh is less featureful than Bash.) What am I missing.
https://web.archive.org/web/20201219013931/https://pubs.open...
Also these operators from C that the author includes. Is he suggesting these are available in POSIX sh.
Quoting from the Pure Sh Bible:
+= Plus-Equal (Increment a variable.)
-= Minus-Equal (Decrement a variable.)
*= Times-Equal (Multiply a variable.)
/= Slash-Equal (Divide a variable.)
%= Mod-Equal (Remainder of dividing a variable.)
> Bitwise Right Shift
>>= Right-Shift-Equal
& Bitwise AND
&= Bitwise AND-Equal
| Bitwise OR
|= Bitwise OR-Equal
~ Bitwise NOT
^ Bitwise XOR
^= Bitwise XOR-Equal
One could probably learn from reading the POSIX standard, the Almquist shell source code and then experimenting. I also like reading other peoples' shell scripts, if they are good. Always something new to learn. Unfortunately this "Bible" did not teach me anything new.