# Remove all leading white-space.
trim=${1#${1%%[![:space:]]*}}
# Remove all trailing white-space.
trim=${trim%${trim##*[![:space:]]}}
Your scientists were so preoccupied with whether they could, they didn't stop to think if they shouldPure Sh Bible
11–20 of 138 posts
Re: Pure Sh Bible
#12I 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…
Re: Pure Sh Bible
#13Re: Pure Sh Bible
#14::looping over a file
The "loop over the contents of a file" entry does not protect stdin.
Use an alternate descriptor.
while read -r line
Particularly problematic is ssh, that will pass $line to any remote command that is able to consume it.The looped commands will receive stdin of the loop when an alternate descriptor is used. I use 9 by habit after reading the flock manual page many years ago.
::EXIT trap
dash will only call the EXIT trap on a normal exit. Add INT (and any other signal that you want from "kill -l") if you also want to catch abnormal terminations.
Windows busybox sh/bash only catches regular exits, no matter what else you add.
Re: Pure Sh Bible
#15Re: Pure Sh Bible
#16I 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…
N="$(printf '\033[')" x=30
for a in Bl R G Y B M C W # 4-bit Black Red Green Yellow Blue Magenta Cyan White
do eval $a='$N'"'"$(( x))"m'" \
b$a='$N'"'"$((60+x))"m'" \
${a}bg='$N'"'"$((10+x))"m'" \
b${a}bg='$N'"'"$((70+x))"m'" # bX=bright Xbg=background bXbg=brgt bgnd
x=$((x+1))
done
N="${N}0m"
printf "$Y${Gbg}I am yellow on green.$N\n"
I pasted this into my Android terminal, and it works as advertised.Re: Pure Sh Bible
#17Mildly 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.
Re: Pure Sh Bible
#18Mildly 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.
Can you explain why you believe it is in poor taste?
Re: Pure Sh Bible
#19If we're going to be purists, sh is a far cry from bash. /s tongue in cheek, please don't kill me. I love bash and I use it often. I love Greg Wooledge's bash guides and all the people in #bash@libera.
Busybox bash does not implement arrays, for starters, which is a deal breaker for many scripts.
The Windows kernel forks processes about 10x slower than Linux, so these tricks have real performance value for POSIX-family shells running there.
Re: Pure Sh Bible
#20Before clicking, I really thought this was some kind of shell command front-end to spit out Bible verses or something. Woops.