该脚本将根据用户输入回显存储在数组中的不同值。但是,输出不正确,并回显了错误的值。
AA_P=/root/run_Scripts/AA_P_run.sh
AA_S=/root/run_Scripts/AA_S_run.sh
read -p "Enter 'P' or 'S'"$'\n' P_S
read -p "How many runs?"$'\n' runs
script="AA${P_S}"
echo $script
echo ""
declare -A Arr=( [AAP]=$AA_P [AAS]=$AA_S )
for key in ${Arr[@]}; do
if [[ $key == $nScript ]]; then
key="${Arr[$key]}"
fi
while [ $runs -gt 0 ]; do
echo $key
(( runs=runs-1 ))
done
done
exit
当输入为'S'和'3'时,输出如下。
AAS
/root/run_Scripts/AA_P_run.sh
/root/run_Scripts/AA_P_run.sh
/root/run_Scripts/AA_P_run.sh
为什么脚本没有回显 ' /root/run_Scripts/AA_S_run.sh?