Dash:
[t2-trunk.git] / misc / luabash / example / example.sh
blob0f6ca1c47237c62e64f7be12a3cced285e87fd3a
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 #
5 # T2 SDE: example.sh
6 # Copyright (C) 2006 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
17 # This is a simple lua bash example.
19 # init lua bash and load code chunk from file internal.lua.
20 enable -f ../luabash.so luabash
21 luabash load ./internal.lua
23 # perform some arithmetic using a lua function called "plus".
24 total=0
25 for ((i=1;i<3;i++)) ; do
26 for ((j=1;j<3;j++)) ; do
27 plus $i $j
28 done
29 done
30 echo "total sum is: " $total
33 # bash function to be called from within lua context
34 some_bashy_function ()
36 if [ -n "$2" ] ; then
37 shift
38 some_bashy_function $@
39 echo "$1"
43 # call the lua function that calls bash function above
44 callbash
46 # test if io redirection works
47 cat <<EOF | redirections | sed 's,xx,yy,g'
48 line one
49 line two
50 line three
51 EOF
53 # print ten shell variables
54 printenv | head -n 10
56 one
57 echo $?
59 zero
60 echo $?
62 str
63 echo $?
65 boolean
66 echo $?