1. Use the following website to get a list of random words: https://randomwordgenerator.com and put them together in a variable
2. Register the start time with `date +%s` and put it in a variable `TSTART`
3. Loop over the words and ask the user to give the number of letters. Echo the answers.
4. Register the end time in `TEND`
5. Display the total run time and the score.
1. In your `bash_exercises` folder create a new bash file called `exercise_3.sh` and make it executable
2. Use the following website to get a list of 10 random words: https://randomwordgenerator.com and put them together in an array
3. Register the start time with `date +%S` and put it in a variable `tstart`
4. Loop over the words and ask the user to give the number of letters. Echo the answers.
5. Register the end time in `tend`
6. Display the total run time and the total number of letters.
---
...
...
@@ -808,8 +802,10 @@ _files="$@"
# Hands-on exercise
<!-- Repartir de l'exercise précédent. Stocker les résultatst dans un fichier au lieu de stdin.
Puis; lire ce fichier pour compter le score. -->
1. In your `bash_exercises` folder, copy `exercise_3.sh` to `exercise_4.sh`
2. In this new file, loop over the words and write the number of letters of each word in a new file called `output.txt`
3. Now loop over the created file `output.txt` to get the total number of letters
4. Display the total run time and the total number of letters
---
...
...
@@ -827,11 +823,10 @@ hello_world () {
}
hello_world
```
Functions must be declared **before** they are used
> defining a function doesn’t execute it
Functions must be declared **before** they are used
---
## Variables Scope
...
...
@@ -919,7 +914,7 @@ print_something Mars
# Hands-on exercise
1. Write a script called `exercise_4.sh` expecting **2 arguments**. If not exactly two arguments are provided, exit with an error and show a "usage" message to the user.
1. Write a script called `exercise_5.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-->