#!/bin/sh

# Create a directory containing nested #! interpreter scripts.
dir=$(mktemp -d) || exit 1

for i in 1 2 3 4 5 6 7 8 9; do
    next=$((i + 1))
    printf '#!%s/s%s\n' "$dir" "$next" > "$dir/s$i"
done

printf '#!/bin/sh\necho "Reached the end"\n' > "$dir/s10"
chmod +x "$dir"/s*

printf 'Scripts created in: %s\n' "$dir"
printf '\nRunning s1 (too many nested interpreters):\n'
"$dir/s1"

printf '\nRunning s7 (shorter chain):\n'
"$dir/s7"

printf '\nInspect them with: ls -l %s\n' "$dir"

