Level 0

examples/0/hello_world.shexamples/0/hello_world.py
#!/bin/dash

echo hello world
#!/usr/bin/python3 -u

print('hello world')

examples/0/hollow.shexamples/0/hollow.py
#!/bin/dash

echo This   is the   way the world ends
echo This is    the way   the world ends
echo This is the    way    the world       ends
echo Not with a     bang but            a        whimper.
#!/usr/bin/python3 -u

print("This is the way the world ends")
print("This is the way the world ends")
print("This is the way the world ends")
print("Not with a bang but a whimper.")

examples/0/truth0.shexamples/0/truth0.py
#!/bin/dash
echo And I told you to be patient
echo And I told you to be fine
echo And I told you to be balanced
echo And I told you to be kind
#!/usr/bin/python3 -u

print('And I told you to be patient')
print('And I told you to be fine')
print('And I told you to be balanced')
print('And I told you to be kind')

examples/0/variables0.shexamples/0/variables0.py
#!/bin/dash

a=hello
b=world

echo $a $b
#!/usr/bin/python3 -u

a = 'hello'
b = 'world'

print(f"{a} {b}")

Level 1

examples/1/cd.shexamples/1/cd.py
#!/bin/dash

cd /tmp
pwd
#!/usr/bin/python3 -u
import os
import subprocess

os.chdir('/tmp')
subprocess.run(['pwd'])

examples/1/for.shexamples/1/for.py
#!/bin/dash

for word in Houston 1202 alarm
do
    echo $word
done
#!/usr/bin/python3 -u

for word in 'Houston', '1202', 'alarm':
    print(word)

examples/1/for_exit.shexamples/1/for_exit.py
#!/bin/dash

for word in Houston 1202 alarm
do
    echo $word
    exit 0
done
#!/usr/bin/python3 -u

import sys

for word in ['Houston', '1202', 'alarm']:
    print(word)
    sys.exit(0)

examples/1/for_gcc.shexamples/1/for_gcc.py
#!/bin/dash

for c_file in *.c
do
    echo gcc -c $c_file
done
#!/usr/bin/python3 -u

import glob

for c_file in sorted(glob.glob("*.c")):
    print('gcc', '-c', c_file)

examples/1/for_read0.shexamples/1/for_read0.py
#!/bin/dash

for n in one two three
do
    read line
    echo Line $n $line
done
#!/usr/bin/python3 -u

for n in ['one', 'two', 'three']:
    line = input()
    print(f"Line {n} {line}")

examples/1/ls-l.shexamples/1/ls-l.py
#!/bin/dash

ls -l /dev/null
#!/usr/bin/python3 -u

import subprocess

subprocess.run(['ls', '-l', '/dev/null'])

examples/1/ls.shexamples/1/ls.py
#!/bin/dash

ls /dev/null
#!/usr/bin/python3 -u

import subprocess

subprocess.run(['ls', '/dev/null'])

examples/1/pwd.shexamples/1/pwd.py
#!/bin/dash

pwd
#!/usr/bin/python3 -u

import subprocess

subprocess.run(['pwd'])

examples/1/single.shexamples/1/single.py
#!/bin/dash

pwd
ls
id
date
#!/usr/bin/python3 -u

import subprocess

subprocess.run(['pwd'])
subprocess.run(['ls'])
subprocess.run(['id'])
subprocess.run(['date'])

Level 2

examples/2/args.shexamples/2/args.py
#!/bin/dash

echo My first argument is $1
echo My second argument is $2
echo My third argument is $3
echo My fourth argument is $4
echo My fifth argument is $5
#!/usr/bin/python3 -u
import sys

print('My', 'first', 'argument', 'is', sys.argv[1])
print('My', 'second', 'argument', 'is', sys.argv[2])
print('My', 'third', 'argument', 'is', sys.argv[3])
print('My', 'fourth', 'argument', 'is', sys.argv[4])
print('My', 'fifth', 'argument', 'is', sys.argv[5])

examples/2/elif.shexamples/2/elif.py
#!/bin/dash

if test Andrew = great
then
    echo correct
elif test Andrew = fantastic
then
    echo yes
else
    echo error
fi
#!/usr/bin/python3 -u

if 'Andrew' == 'great':
    print('correct')
elif 'Andrew' == 'fantastic':
    print('yes')
else:
    print('error')

examples/2/filetest0.shexamples/2/filetest0.py
#!/bin/dash

if test -r /dev/null
then
    echo a
fi

if test -r nonexistantfile
then
    echo b
fi
#!/usr/bin/python3 -u

import os

if os.access('/dev/null', os.R_OK):
    print('a')

if os.access('nonexistantfile', os.R_OK):
    print('b')

examples/2/filetest1.shexamples/2/filetest1.py
#!/bin/dash

if test -d /dev/null
then
    echo /dev/null
fi

if test -d /dev
then
    echo /dev
fi
#!/usr/bin/python3 -u

import os

if os.path.isdir('/dev/null'):
    print('/dev/null')

if os.path.isdir('/dev'):
    print('/dev')

examples/2/if.shexamples/2/if.py
#!/bin/dash

if test Andrew = great
then
    echo correct
else
    echo error
fi
#!/usr/bin/python3 -u

if 'Andrew' == 'great':
    print('correct')
else:
    print('error')

examples/2/single_quotes.shexamples/2/single_quotes.py
#!/bin/dash

echo 'hello world'
#!/usr/bin/python3 -u

print('hello world')

examples/2/truth2.shexamples/2/truth2.py
#!/bin/dash
echo 'When old age shall this generation waste,'
echo 'Thou shalt remain, in midst of other woe'
echo 'Than ours, a friend to man, to whom thou sayst,'
echo '"Beauty is truth, truth beauty",  -  that is all'
echo 'Ye know on earth, and all ye need to know.'
#!/usr/bin/python3 -u
print('When old age shall this generation waste,')
print('Thou shalt remain, in midst of other woe')
print('Than ours, a friend to man, to whom thou sayst,')
print('"Beauty is truth, truth beauty",  -  that is all')
print('Ye know on earth, and all ye need to know.')

examples/2/while0.shexamples/2/while0.py
#!/bin/dash

status=off
while test $status != on
do
    echo status is $status
    status=on
done
#!/usr/bin/python3 -u

status = 'off'
while status != 'on':
    print(f'status is {status}')
    status = 'on'

examples/2/while1.shexamples/2/while1.py
#!/bin/dash

row=1
while test $row != 11111111111
do
    echo $row
    row=1$row
done
#!/usr/bin/python3 -u

row = '1'
while row != '11111111111':
    print(row)
    row = f'1{row}'

Level 3

examples/3/backticks0.shexamples/3/backticks0.py
#!/bin/dash

a=`printf hi`
echo $a
#!/usr/bin/python3 -u

import subprocess

a = subprocess.run(['printf', 'hi'], text=True, stdout=subprocess.PIPE).stdout
print(' '.join(a.strip().split()))

examples/3/double_quotes.shexamples/3/double_quotes.py
#!/bin/dash

echo "hello world"
#!/usr/bin/python3 -u

print("hello world")

examples/3/l.shexamples/3/l.py
#!/bin/dash

ls -las "$@"
#!/usr/bin/python3 -u

import subprocess
import sys

subprocess.run(['ls', '-las'] + sys.argv[1:])

examples/3/sequence0.shexamples/3/sequence0.py
#!/bin/dash

# print a contiguous integer sequence

start=$1
finish=$2

number=$start
while test $number -le $finish
do
    echo $number
    number=`expr $number + 1`  # increment number
done
#!/usr/bin/python3 -u

import subprocess
import sys

# print a contiguous integer sequence

start = sys.argv[1]
finish = sys.argv[2]

number = start
while int(number) <= int(finish):
    print(number)
    number = subprocess.run(['expr', number, '+', '1'], text=True, stdout=subprocess.PIPE).stdout.rstrip('\n') # increment number

examples/3/while1.shexamples/3/while1.py
#!/bin/dash

x='###'
while test $x != '########'
do
    y='#'
    while test $y != $x
    do
        echo $y
        y="${y}#"
    done
    x="${x}#"
done
#!/usr/bin/python3 -u

x = '###'
while x != '########':
    y = '#'
    while y != x:
        print(y)
        y = f"{y}#"
    x = f"{x}#"

examples/3/while2.shexamples/3/while2.py
#!/bin/dash

x='###'
while test $x != '########'
do
    y='#'
    while test $y != $x
    do
        echo $y
        y="${y}#"
    done
    x="${x}#"
done
#!/usr/bin/python3 -u

x = "###"
while x != "########":
    y = '#'
    while y != x:
        print(y)
        y = f"{y}#"
    x = f"{x}#"

examples/3/while_if0.shexamples/3/while_if0.py
#!/bin/dash

status=off
while test "$status" != on
do
    echo "status is $status"
    if test "$status" = "half on"
    then
        status="on"
    else
        status="half on"
    fi
done
#!/usr/bin/python3 -u

status = 'off'
while status != 'on':
    print(f'status is {status}')
    if status == 'half on':
        status = 'on'
    else:
        status = 'half on'

Level 4

examples/4/filetest2.shexamples/4/filetest2.py
#!/bin/dash

if [ -d /dev/null ]
then
    echo /dev/null
fi

if [ -d /dev ]
then
    echo /dev
fi
#!/usr/bin/python3 -u

import os

if os.path.isdir('/dev/null'):
    print('/dev/null')

if os.path.isdir('/dev'):
    print('/dev')

examples/4/sequence1.shexamples/4/sequence1.py
#!/bin/dash
# print a contiguous integer sequence
start=$1
finish=$2

number=$start
while [ $number -le $finish ]
do
    echo $number
    number=$((number + 1))  # increment number
done
#!/usr/bin/python3 -u
import sys
# print a contiguous integer sequence
start = sys.argv[1]
finish = sys.argv[2]

number = start
while int(number) <= int(finish):
    print(number)
    number = int(number) + 1  # increment number

examples/4/series.shexamples/4/series.py
#!/bin/dash
start=13
if test $# -gt 0
then
    start=$1
fi
i=0
number=$start
file=./tmp.numbers
rm -f $file
while true
do
    if test -r $file
    then
        if fgrep -x -q $number $file
        then
            echo Terminating: series is repeating
            exit 0
        fi
    fi
    echo $number >>$file
    echo $i $number
    k=`expr $number % 2`
    if test $k -eq 1
    then
        number=`expr 7 '*' $number + 3`
    else
        number=`expr $number / 2`
    fi
     i=`expr $i + 1`
    if test $number -gt 100000000 -o  $number -lt -100000000
    then
        echo Terminating: too large
        exit 0
    fi
done
rm -f $file
#!/usr/bin/python3 -u
import os
import subprocess
import sys
start = 13
if len(sys.argv[1:]) > 0:
    start = sys.argv[1]
i = 0
number = start
file = './tmp.numbers'
subprocess.run(['rm', '-f', str(file)])
while not subprocess.run(['true']).returncode:
    if os.access(file, os.R_OK):
        if not subprocess.run(['fgrep', '-x', '-q', str(number), str(file)]).returncode:
            print('Terminating:', 'series', 'is', 'repeating')
            sys.exit(0)
    with open(file, 'a') as f:
        print(number, file=f)
    print(i, number)
    k = int(number) % 2
    if k == 1:
        number = 7 * int(number) + 3
    else:
        number = int(number) // 2
    i = i + 1
    if int(number) > 100000000 or int(number) < -100000000:
        print('Terminating:', 'too', 'large')
        sys.exit(0)
subprocess.run(['rm', '-f', str(file)])