Create a script for PlayOnLinux - Chapter 3 : the variables

Variable ? Is that a new insult ?

No, it's not an insult. The variable is a very important element in programming. It is defined by a name and a value. This value can vary along the script.

If you don't understand, keep on reading and you'll find out what it's all about.

Declaring a variable

There are to options to declare a variable in bash :

1st case :

MY_VARIABLE="My value"

2nd case :

export MY_VARIABLE="My value"

In the first instance, only the actual script will be able to read the value. In the second one, all programms and scriptst opened from yours will be able to read this variable

What's its use ?

You'll get an answer in the next paragraph

Reading a variable

You have to put this sign "$" in front of the variable.

Here's an example of code :

PSEUDO="Tinou"
POL_SetupWindow_message "$PSEUDO is the strongest" "Name of the strongest"

Résult :

You can use variables in any function, echo, message, question, menu, ...

PlayOnLinux and variables

Do you remember this code ?

POL_SetupWindow_menu "What do you want to eat tonight ?" "Tonight's menu" "Carrots Potatoes French-fries" " "

The result is actually sent in the variable $APP_ANSWER. This is the way to retrieve your variable :

POL_SetupWindow_menu "What do you want to eat tonight ?" "Tonight's menu" "Carrots Potatoes French-fries" " "
MY_MEAL=$APP_ANSWER
POL_SetupWindow_message "Tonight we'll be eating $MY_MEAL" "Tonight's menu"

The variable $APP_ANSWER is created with each PlayOnLinux functions that involves a choice from the user.

For POL_SetupWindow_question, $APP_ANSWER is either TRUE or FALSE depending on the answer.

Previous chapter - Next chapter

Il n'y a rien à voir ici