Skip to content
Extraits de code Groupes Projets
Valider 2ce93a8c rédigé par Pierre-Yves Barriat's avatar Pierre-Yves Barriat
Parcourir les fichiers

New slides after merge request

parent ba99d2b2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -160,6 +160,7 @@ $ cd myfolder || ls # if failed cd to myfolder, `ls` will run
---
-->
# Permissions and execution
- Bash script is nothing else just a **text file** containing instructions to be executed sequentially
......@@ -177,9 +178,9 @@ $ cd myfolder || ls # if failed cd to myfolder, `ls` will run
Your first bash script:
1. create a folder `bash_exercises` and go there
1. use your favourite editor (vim, obviously) to create a new file called `exercise_1.sh`
1. write some code in it to display the current working directory as:
> The current directory is : /home/me/bash_exercises
2. use your favourite editor (vim, obviously) to create a new file called `exercise_1.sh`
3. write some code in it to display the current working directory as:
> The current directory is : /home/me/bash_exercises
4. make the file executable
5. run it !
......@@ -239,7 +240,7 @@ myvar=$( ls )
* Avoid using **reserved keywords**, such as `if`, `then`, `else`, `fi`, and so on...
* **Never** name your private variables using only **UPPERCASE** characters to avod conflicts with builtins
* **Never** name your private variables using only **UPPERCASE** characters to avoid conflicts with builtins
---
......@@ -253,6 +254,7 @@ myvar=$( ls )
| `%` | modulus (remainder after division) |
Several ways to go about arithmetic in Bash scripting :
`let`, `expr` or using **double parentheses**
<!-- JDF: probablement pas la bonne place pour ça
......@@ -424,7 +426,7 @@ esac
1. In your `bash_exercises` folder create a new bash file called `exercise_2.sh` and make it executable
2. Ask the user for two numbers smaller or equal to 100, put them in variables `NUMBER1` and `NUMBER2`
3. Do the following only if the number are smaller than 100:
3. Do the following only if the number are smaller than 100
4. Check if at least one of the numbers is a multiple of 3, and tell the user
5. Otherwise, check if both numbers are even, and tell the user
6. If the user's numbers ar too big, tell them
......@@ -470,7 +472,6 @@ The variable expansion `${MYVAR+ABC}` expands to "ABC" is `MYVAR` is set and to
declare -A countries=( [ALB]=Albania [BHR]=Bahrain [CMR]=Cameroon [DNK]=Denmark [EGY]=Egypt )
echo ${countries[@]}
echo ${!countries[@]}
countries+=( [FJI]=Fiji )
echo ${countries[@]}
unset countries[BHR]
......@@ -589,7 +590,7 @@ Speed game:
3. Loop over the words and ask the user to give the number of letters. Put the answers in an associative array using the words as keys and the answers as values
4. Register the end time in `TEND`
5. Display the total run time
6. Loop over the associative array to compute the score (number of good answers) and show it to the user.
6. Loop over the associative array to compute the score (number of good answers) and show it to the user
---
......@@ -891,7 +892,7 @@ ls
1. Write a script called `exercise_3.sh` expecting **2 arguments**. If not exactly two arguments are provided, exit with an error and show a "usage" message to the user.
2. Write a function taking a **folder path** and an **extension** as arguments and giving the list of matching files to the user
3. Imagine you are running jobs taking data from two folders, each with a dedicated extension. Use the two arguments of the script as the name of the two folders and **get the two lists of files**.
4. Since your work needs to read these files, **check that all files can be read**. If some files cannot be read, display their name to the user.
4. Since your work needs to read these files, **check that all files can be read**. If some files cannot be read, display their name to the user
---
......
Aucun aperçu pour ce type de fichier
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter