다른 스크립트에서 사용자 입력을 요청할 수 있는 bash 스크립트를 호출하는 방법

다른 스크립트에서 사용자 입력을 요청할 수 있는 bash 스크립트를 호출하는 방법

두 개의 스크립트가 있는데 하나는 다른 하나를 호출하고 어떤 경우에는 호출된 스크립트가 사용자 입력을 요청할 수 있습니다. 현재 저는 이 스크립트를 실행하고 있지만 입력을 기다리지도 않습니다. 이 스크립트를 올바르게 호출하고 사용자와의 통신을 전달하려면 어떻게 해야 합니까?

주요 스크립트:

#!/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

관련 정보