i am just wondering is there anyway to source a file and then down in track source the file again?
I am using https://github.com/renatosilva/easyoptions on my bash script, i am sourcing easyoption.sh on the main script and which works fine. but when i have other scripts which gets loaded later on from the main script, i want easyoptions.sh to be sourced and --help should work on the last loaded file.
example:
test.sh
#!/bin/bash
## EasyOptions Sub Test
## Copyright (C) Someone
## Licensed under XYZ
## -h, --help All client scripts have this, it can be omitted.
script_dir=$(dirname "$BASH_SOURCE")
# source "${script_dir}/../easyoptions" || exit # Ruby implementation
source "${script_dir}/easyoptions.sh" || exit # Bash implementation, slower
main.sh
#!/bin/bash
## EasyOptions Main
## Copyright (C) Someone
## Licensed under XYZ
## Options:
## -h, --help All client scripts have this, it can be omitted.
## --test This loads test.sh.
script_dir=$(dirname "$BASH_SOURCE")
# source "${script_dir}/../easyoptions" || exit # Ruby implementation
source "${script_dir}/easyoptions.sh" || exit # Bash implementation, slower
if [[ -n "$test" ]];then
source "${script_dir}/test.sh"
fi
Now when i try ./main.sh --help it displays
EasyOptions Main
Copyright (C) Someone
Licensed under XYZ
Options:
-h, --help All client scripts have this, it can be omitted.
> --test This loads test.sh.
Now i want below to work ./main.sh --test --help and it should output
EasyOptions Sub Test
Copyright (C) Someone
Licensed under XYZ
-h, --help All client scripts have this, it can be omitted.
But instead it always displays main.sh help