mardi 25 juillet 2017

How continue processing shell script after respect of condition

in my shell script, I am asking a question and verifying the result with 2 conditions. What is I wanna do is to continue reading the rest of script if these conditions are true otherwise the question must always be asking user.

Other thing, it must be a function because I will use it many times.

And I purposely simplified the code:

#!/bin/bash

t="5"

function ask_version {
while true ; do

echo -ne "\033[32m$1\033[0m : "
read -n 1 -r

if [[ ! $REPLY =~ ^[0-9] ]] ; then
  echo -e " Please respect number format"
elif [[ $t -ne $REPLY ]] ; then
  echo -e "It is not the true number"
else
  return 0
fi

done
}

ask_version "Please type a number"
if [[ $? = 0 ]]
#Here I wanna do the test, if true I continue...
fi

Aucun commentaire:

Enregistrer un commentaire