I was wondering if there are general guidelines for optimizing bash script.
a) For example, it is more convenient to write loops than lines of commands, but is it also faster to process for the system? Example:
for i in a b c; do echo $i; done
echo a
echo b
echo c
b) Sometimes people present different solutions for the same problem. For example, sed, cut, awk, and echo are all able to strip digits from a string. I was wondering if you can say that the less digits a code has, the faster it is if you use:
i) the same command, e.g.
STRING=abc.def
echo ${STRING} | sed 's/.def//g'
echo ${STRING} | sed '$s/....$//'
ii) different commands, e.g.
STRING=abc.def
echo ${STRING} | cut -d . -f 1
echo ${STRING} | sed 's/.def//g'