Create a script for PlayOnLinux - Chapter 4: Some conditions

Some conditions? Is it eatable?

If you are very hungry, why not. More seriously, a condition will allow you to make your script do different things depending on a test. For example, depending on a variable's value

An example is always better to understand

We will use the if command

MY_MEAL=$(menu "What do you want to eat this evening?" "Carrots Potatoes Chips")
if [ "$MY_MEAL" = "Carrots" ]
then
   message "Let's eat"
fi

The message "Let's eat" will be displayed only if the user chooses Carrots

MY_MEAL=$(menu "What do you want to eat this evening?" "Carrots Potatoes Chips")
if [ "$MY_MEAL" = "Carrots" ]
then
   message "I'm on a hunger strike"
else
   message "Can I have some more?"
fi

The message "I'm on a hunger strike" will be displayed only if the user chooses Carrots. Else, it's the "Can I have more?" message that appears

Il n'y a rien à voir ici