Shells in OCaml
at main 53 lines 837 B view raw
1Testing functions and position arguments. 2 3First is simply that the original positional arguments are preserved. 4 5 $ cat > test.sh << EOF 6 > echo "\$1 from \$0" 7 > EOF 8 9 $ sh test.sh hello 10 hello from test.sh 11 $ msh test.sh hello 12 hello from test.sh 13 14Next, do they work inside function definitions! 15 16 $ cat > test.sh << EOF 17 > shout () { 18 > echo \$0 19 > echo \$1 | tr a-z A-Z 20 > } 21 > shout "hi there" 22 > EOF 23 24 $ sh test.sh 25 test.sh 26 HI THERE 27 $ msh test.sh 28 test.sh 29 HI THERE 30 31Redirection and exit codes should be preserved to just like any other command. 32 33 $ cat > test.sh << EOF 34 > goodbye () { 35 > echo "eybdoog" 36 > exit \$1 37 > } 38 > goodbye 0 | rev 39 > goodbye 1 | rev 40 > goodbye 128 41 > EOF 42 43 $ sh test.sh 44 goodbye 45 goodbye 46 eybdoog 47 [128] 48 49 $ msh test.sh 50 goodbye 51 goodbye 52 eybdoog 53 [128]