You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
1.7 KiB
102 lines
1.7 KiB
#!/usr/bin/env miaou-bash
|
|
|
|
# CONSTANTS
|
|
|
|
BASEDIR=$(dirname "$0")
|
|
readonly BASEDIR
|
|
|
|
# SCENARII
|
|
|
|
function do_success {
|
|
echo -n 'SUCCESS args=['
|
|
(
|
|
IFS=','
|
|
echo -n "$*"
|
|
)
|
|
echo ']'
|
|
}
|
|
|
|
function do_unbound_variable {
|
|
a=5
|
|
echo "a=${a}"
|
|
echo "b=${b}"
|
|
}
|
|
|
|
# FUNCTIONS
|
|
|
|
function F2 {
|
|
echo "stdout A"
|
|
# echo toto >>/tmp/toto
|
|
return
|
|
>&2 echo "This is stderr"
|
|
|
|
blabla
|
|
$nope
|
|
exit 6
|
|
grep titi toto
|
|
echo "stdout B"
|
|
echo "stdout C"
|
|
# command_not_found
|
|
}
|
|
|
|
function F1 {
|
|
echo F1
|
|
F2
|
|
}
|
|
|
|
function main {
|
|
F1
|
|
F3
|
|
echo before subshell
|
|
echo "here in subshell $(grep titi $0)"
|
|
echo NO MORE
|
|
|
|
result=$(grep titi $0)
|
|
[[ "$result" -ne 0 ]] && echo true
|
|
# grep titi nope
|
|
>&2 echo some trace in stderr1
|
|
"$BASEDIR/extra/library.bash"
|
|
. "$BASEDIR/lib/utility.bash"
|
|
# . not_found/not_found.bash
|
|
# echo "here in subshell $(grep titi nope)"
|
|
# ls -l nope
|
|
>&2 echo some trace in stderr2
|
|
}
|
|
|
|
function F3 {
|
|
echo F3
|
|
return 0
|
|
}
|
|
|
|
function usage {
|
|
introspect_scenarii
|
|
(
|
|
IFS='|'
|
|
echo "USAGE: $0 <${SCENARII[*]}>"
|
|
)
|
|
echo -e "\trun case scenario which performs various bash statements and mostly fails"
|
|
echo -e "\tthese case scenarii helps testing the miaou-bash script"
|
|
}
|
|
|
|
function introspect_scenarii {
|
|
mapfile -t SCENARII <<<"$(compgen -A function | grep ^do_ | sed 's/...//')"
|
|
}
|
|
|
|
function test_contain_item {
|
|
local -n array=$1
|
|
for item in "${array[@]}"; do [[ "$item" == "$2" ]] && return 0; done
|
|
return 1
|
|
}
|
|
|
|
# MAIN
|
|
|
|
[[ $# -eq 0 ]] && >&2 echo 'arg1 expected!' && usage && exit 1
|
|
|
|
scenario="$1"
|
|
introspect_scenarii
|
|
if test_contain_item SCENARII "$scenario"; then
|
|
shift
|
|
"do_${scenario}" "$@"
|
|
else
|
|
(>&2 echo "scenario <${scenario}> not found!" && usage && exit 2)
|
|
fi
|