Shells in OCaml
1Case compound command
2
3 $ cat > test.sh << EOF
4 >
5 > service () {
6 > case "\$1" in
7 > start|begin)
8 > echo "Starting up service..."
9 > ;;
10 > status)
11 > echo "All good..."
12 > ;;
13 > stop)
14 > echo "Stopping service"
15 > ;;
16 > *)
17 > echo "Unknown command: \$1"
18 > ;;
19 > esac
20 > }
21 >
22 > service start
23 > service status
24 > service stop
25 > service foo
26 >
27 > EOF
28
29 $ sh test.sh
30 Starting up service...
31 All good...
32 Stopping service
33 Unknown command: foo
34
35 $ msh test.sh
36 Starting up service...
37 All good...
38 Stopping service
39 Unknown command: foo
40
41
42 $ cat > test.sh << EOF
43 > contains () {
44 > case \$1 in
45 > *\$2*)
46 > echo "Yep, \$2 is in \$1"
47 > ;;
48 > *)
49 > echo "\$1 does not contain \$2"
50 > ;;
51 > esac
52 > }
53 >
54 > contains "radar" "ada"
55 > contains "hello" "ee"
56 > EOF
57
58 $ sh test.sh
59 Yep, ada is in radar
60 hello does not contain ee
61 $ msh test.sh
62 Yep, ada is in radar
63 hello does not contain ee