Tim Hatch

Weblog | Photos | Projects | Panoramas | About

About

My everyday development environment consists of a lot of different machines -- OS X Leopard, OS X Snow Leopard, Arch Linux, Gentoo Linux, Debian Linux, Ubuntu Linux, mingw on win32, (cygwin on win32, shudder), and embedded systems with busybox (or toolbox, on my G1).

These all can use slightly different versions of shells, and I like to keep my scripts portable so if I had to run a different one, it wouldn't be painful. It also helps with CI software to be able to add new buildslaves at any time.

Command        Bash 3.x  Zsh  Dash  Busybox
-------        --------  ---  ----  -------
echo {1..3}    YES       YES  no    no
seq 1 3 -- coreutils?
jot 3 -- bsd
perl -e "print join ' ', 1..3" -- anywhere with perl

Command Output Bash 3.x  Zsh  Dash  Busybox  Sh
-------        --------  ---  ----  -------  --
`echo 1`       YES       YES  YES   YES      YES
$(echo 1)      YES       YES  YES   YES      no


Math operation Bash 3.x  Zsh  Dash  Busybox
-------        --------  ---  ----  -------
$(( $x + 1 ))  YES       YES  YES   YES
let t="$x+1"   YES       no   no    YES
echo "1 + 2" | bc
echo "$x 1 + p" | dc

Spaces in filesBash 3.x  Zsh  Dash  Busybox
-------        --------  ---  ----  -------
ls | while read r; do echo "$r"; done
               YES       no   YES   YES
IFS="\n"; for f in `ls`; do echo "$f"; done
               YES       YES  YES   YES

Dir of a scriptBash 3.x  Zsh  Dash  Busybox
-------        --------  ---  ----  -------
x=$(cd `dirname $0`; pwd)
               YES       ??   ??    ??

Predicated removal
------------------
find . -name '*.pyc' | while read r; do if [ ! -f `echo $$r | sed -e 's/pyc$/py/'` ]; then rm "$r"; done
find . -name '*.pyc' | while read r; do if [ ! -f "${r/%pyc/py}" ]; then rm "$r"; done

Catting a file
--------------
cat filename -- everywhere except an openwrt micro build
grep -v IMPOSSIBLE filename

Copying a file
--------------
cp file newfile -- anywhere except stock G1
cat file > newfile
install ...