![다른 스크립트에서 사용자 입력을 요청할 수 있는 bash 스크립트를 호출하는 방법](https://linux55.com/image/160815/%EB%8B%A4%EB%A5%B8%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EC%97%90%EC%84%9C%20%EC%82%AC%EC%9A%A9%EC%9E%90%20%EC%9E%85%EB%A0%A5%EC%9D%84%20%EC%9A%94%EC%B2%AD%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%8A%94%20bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A5%BC%20%ED%98%B8%EC%B6%9C%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
두 개의 스크립트가 있는데 하나는 다른 하나를 호출하고 어떤 경우에는 호출된 스크립트가 사용자 입력을 요청할 수 있습니다. 현재 저는 이 스크립트를 실행하고 있지만 입력을 기다리지도 않습니다. 이 스크립트를 올바르게 호출하고 사용자와의 통신을 전달하려면 어떻게 해야 합니까?
주요 스크립트:
#!/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