我只是想知道有无论如何来源文件,然后再次追踪源文件?Bash脚本重新源文件
我在我的bash脚本上使用https://github.com/renatosilva/easyoptions,我在主脚本上找到easyoption.sh,并且工作正常。但是当我有其他脚本从主脚本稍后加载时,我想要easyoptions.sh来源,并且--help应该在最后加载的文件上工作。
例如:
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
现在,当我尝试 ./main.sh --help 它显示
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.
现在我想下面的工作 ./main.sh --test --help ,它应该输出
EasyOptions Sub Test
Copyright (C) Someone
Licensed under XYZ
-h, --help All client scripts have this, it can be omitted.
但相反,它总是显示main.sh帮助
真的,我必须解决它。 –