我只是想知道有無論如何來源文件,然後再次追蹤源文件?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幫助
真的,我必須解決它。 –