-1

I am new to BASH, well scripting in general, and am writing a BASH script but no idea what to do

I have a script working currently, where with specifics user inputs, it writes a file for a subsequent software to work.

However, specific numbers and phrases are needed for the software to work, so I want to write an error message, that if the input isn't correct, instead of the script failing and starting from scratch, an error message is shown and you have a redo

##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}"

1 Answers1

0

Use 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"

Will ask for input until it's non-empty.

Matthieu
  • 2,736
  • 4
  • 57
  • 87