ユーザーに値の確認を発行してもらいたい構成変数が多数あります。そのため、実行番号を指定する変数が存在する可能性があり、スクリプトでユーザーに変数の現在の値が問題ないかどうかを尋ねます。ユーザーが値に問題があると応答すると、スクリプトは新しい値を要求し、それを変数に割り当てます。
これを行うための関数を最初に試みましたが、実行に問題があります。それは失速します。問題を解決するための支援と、私が使用しているアプローチに対する批判を歓迎します。コードは次のとおりです。
confirmVariableValue(){
variableName="${1}"
variableValue="${!variableName}"
while [[ "${userInput}" != "n" && "${userInput}" != "y" ]]; do
echo "variable "${variableName}" value: "${variableValue}""
echo "Is this correct? (y: continue / n: change it / other: exit)"
read userInput
# Make the user input lowercase.
userInput="$(echo "${userInput}" | sed 's/\(.*\)/\L\1/')"
# If the user input is "n", request a new value for the variable. If the
# user input is anything other than "y" or "n", exit. If the user input
# is "y", then the user confirmation loop ends.
if [[ "${userInput}" == "n" ]]; then
echo "enter variable "${variableName}" value:"
read variableValue
elif [[ "${userInput}" != "y" && "${userInput}" != "n" ]]; then
echo "terminating"
exit 0
fi
done
echo "${variableValue}"
}
myVariable="run_2014-09-23T1909"
echo "--------------------------------------------------------------------------------"
echo "initial variable value: "${myVariable}""
myVariable="$(confirmVariableValue "myVariable")"
echo "final variable value: "${myVariable}""
echo "--------------------------------------------------------------------------------"