diff --git a/Bash.md b/Bash.md index 7ae6a8ac108e95b933f141b1f723f22580fae95f..60d1b137f41305074a33ce4f021366ae7c2e4f82 100644 --- a/Bash.md +++ b/Bash.md @@ -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 --- diff --git a/Bash.pdf b/Bash.pdf index 8cb5993a64b75d471669475f421c0052383ce462..e5c93ff3e2750897b44b1afd0e41b547691ca0c0 100644 Binary files a/Bash.pdf and b/Bash.pdf differ