
2つのスクリプトがあり、一方は別のものを呼び出し、場合によっては呼び出されたスクリプトがユーザー入力を要求できます。現在私はこのスクリプトを実行していますが、入力を待っていません。このスクリプトを正しく呼び出してユーザーとの通信を転送するにはどうすればよいですか?
主なスクリプト:
#!/usr/bin/env bash
script_dir=$(dirname "${0}")
hook_name=$(basename "${0}")
hook_dir="${script_dir}/${hook_name}.d"
if [[ -d ${hook_dir} ]]; then
for hook in "${hook_dir}"/*; do
"${hook}" "${@}"
exit_code=${?}
if [ ${exit_code} != 0 ]; then
error=$(tput setaf 1)
normal=$(tput sgr0)
script_name=$(basename "${hook}")
echo "${error}Hook ${hook_name} : ${script_name} failed!${normal}"
exit ${exit_code}
fi
done
fi
exit 0
ファイル名:
#!/usr/bin/env bash
files=("hooks/install.sh" "hooks/install.bat")
changed=$(git diff --cached --name-only)
for file in "${files[@]}"; do
if [[ ${changed} == *"${file}"* ]]; then
error=$(tput setaf 1)
normal=$(tput sgr0)
message="${error}You have changed one of the files that supposed to work identically!${normal}: [ ${files[*]} ]"
echo "${message}"
read -r -p "Are you sure you want to continue? [y/N]: " response
response=${response,,}
if [[ $response =~ ^(no|n) ]] || [[ -z $response ]]; then
exit 1
fi
fi
done
exit 0