我是BASH的新手,总体来说脚本编写良好,并且正在编写BASH脚本,但不知道该怎么做
我目前正在使用一个脚本,其中在特定用户输入下,它编写了一个文件供后续软件使用。
但是,软件需要特定的数字和短语才能运行,因此我想编写一条错误消息,即如果输入不正确,而不是脚本失败并从头开始,则会显示错误消息你有重做
##Writing inp.add Files##
printf "\n${bold}Writing inp.add file\n${normal}"
read -p "Number of Processors: " NPROC
read -p "Wavefunction File (with .wfx): " WFX
read -p "Coord file (CUBE or .txt): " COORD
echo "AOM_MAT OCCUP automatically picked"
read -p "Overlap (LO or LDO): " OVERLAP
printf "\nRunning Gaussian: ${bold}$JOBNAME \n${normal}"
答案 0 :(得分:0)
使用while cond ; do ... done
:
while true ; do
read -p "Input var: " var
[[ -n "$var" ]] && break
echo "Please enter a non-empty value"
done
echo "You entered $var"
将要求输入,直到它为非空为止。