From fcbed984d8c57e4d2951bf5de8a91dcc51e8f2ab Mon Sep 17 00:00:00 2001 From: dig Date: Tue, 23 Apr 2019 20:07:41 +0200 Subject: [PATCH] Update the Bash example with the multi source files option * Usage of $easyoptions_include in bash/example.sh * The example sourced scripts bash/some_sourced_lib.sh and bash/that_other_lib.sh --- bash/example.sh | 11 +++++++++-- bash/some_sourced_lib.sh | 5 +++++ bash/that_other_lib.sh | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 bash/some_sourced_lib.sh create mode 100644 bash/that_other_lib.sh diff --git a/bash/example.sh b/bash/example.sh index 0700d24..6d39e6d 100644 --- a/bash/example.sh +++ b/bash/example.sh @@ -21,8 +21,9 @@ ## format. script_dir=$(dirname "$BASH_SOURCE") - source "${script_dir}/../easyoptions" || exit # Ruby implementation -# source "${script_dir}/easyoptions.sh" || exit # Bash implementation, slower + easyoptions_include="${script_dir}/some_sourced_lib.sh ${script_dir}/that_other_lib.sh" +# source "${script_dir}/../easyoptions" || exit # Ruby implementation + source "${script_dir}/easyoptions.sh" || exit # Bash implementation, slower # Boolean and parameter options [[ -n "$some_option" ]] && echo "Option specified: --some-option" @@ -33,3 +34,9 @@ for argument in "${arguments[@]}"; do echo "Argument specified: $argument" done + +source "${script_dir}/some_sourced_lib.sh" +some-lib-feature + +source "${script_dir}/that_other_lib.sh" +that-other-feature diff --git a/bash/some_sourced_lib.sh b/bash/some_sourced_lib.sh new file mode 100644 index 0000000..ac331c3 --- /dev/null +++ b/bash/some_sourced_lib.sh @@ -0,0 +1,5 @@ +## -s, --some-lib-option This is an additional option. +some-lib-feature() +{ + [[ -n "$some_lib_option" ]] && echo "Some lib option: $some_lib_option" +} diff --git a/bash/that_other_lib.sh b/bash/that_other_lib.sh new file mode 100644 index 0000000..79f6a76 --- /dev/null +++ b/bash/that_other_lib.sh @@ -0,0 +1,6 @@ +## -t, --that-option That is the option. +that-other-feature() +{ + [[ -n "$that_option" ]] && echo "That other option: $that_option" +} +