1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/bin/dash
# file: hello_world2
# copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
# license: GNU General Public License, version 3
# description: example "hello world" script with function, debug and check
# warning: normally it makes
# warning: Be aware that the interactive step size in this example is only
# reasonable to summanrized demonstrate shellia features.
# Read shellia(7) NOTES, to learn about a reasonable size of
# interactive steps.
# usage: ./hello_world2 [-d] [-i|-s|-m] [--] <name>
# create and use logfile
ia_logfile="$(mktemp)"
export ia_logfile
# we prefer a local copy of ia, if it exists
[ -f ia ] && . ./ia || . /usr/share/shellia/ia
# write_file <path> <name>
write_file()
{
eval "$ia_init"
ia_add "echo \"hello $2\" >$1"
ia -c -x
}
# show_file <path>
show_file()
{
eval "$ia_init"
ia_stdout "^hello" # only allow a greeting starting with hello
ia_add "cat $1"
ia -c -x
}
# initialize shellia
eval "$ia_init"
# get name from commandline
if [ $# -ne 1 ]; then
echo "Usage $0 <name>" >&2
exit 1
fi
ia_add "file=\"\$(mktemp)\""
ia_add "write_file <-i> -- \"\$file\" \"$1\""
ia_stdout "." # allow all kind of output already checked in show_file
ia_add "show_file <-i> -- \"\$file\""
ia_add "rm -f \"\$file\""
ia -c -x
# output logfile
echo "----"
cat $ia_logfile
echo "----"
rm $ia_logfile
|