mardi 13 décembre 2016

BASH - Read user input and then store in a variable for use in other if statements

Anyone know how to store a user's input and then be able to echo that in other if statements WITHIN a while loop.

example:

max=1
while [ "$max" = 0 ]
do
   read input
   echo $input
   ((max=max+1))
done

if [ $input == "text" ]
echo
     "Oh wow some text here"
     "This is a bad example I'm sorry"
fi

Basically how would I be able to store $input and then use it in future if statements, that example is pretty bad but this is the scenario:


I have a while loop.

Inside that while loop I have an if statement

Inside that if statement I have a read command that takes user input

Let's say it is 'CREATE PASSWORD' and IF THE USER TYPES IN CREATE PASSWORD then it will take them to that if statement which creates the password

Another if statement changes the password and the user can also access this through typing in 'change password' in the command.

How would I make it so that I could use the same password input as a sort of value or just something that comes up twice in different if statements?

Aucun commentaire:

Enregistrer un commentaire