#!/bin/sh
# nest.sh: s1 has s0 as its interpreter, s2 has s1, and so on
#   usage: sh nest.sh

dir=$(mktemp -d)
cd "$dir" || exit 1
printf '#!/bin/sh\necho "works: $0 $*"\n' > s0
chmod +x s0
i=1
while [ $i -le 7 ]; do
    echo "#!./s$((i - 1))" > s$i
    chmod +x s$i
    printf 's%d: ' $i
    ./s$i
    i=$((i + 1))
done
rm -r "$dir"
