From 768f97e4a42534880badc2219b6f74cbb1efbd5d Mon Sep 17 00:00:00 2001 From: miguel Date: Tue, 4 Apr 2023 18:25:57 +0100 Subject: [PATCH] docs(bin-status): fix the usage of bin status format readmes of other exercises --- subjects/devops/bin-status/README.md | 8 +++++--- subjects/devops/calculator/README.md | 24 +++++++++++++---------- subjects/devops/check-user/README.md | 6 +++++- subjects/devops/custom-ls/README.md | 18 +++++++++++------ subjects/devops/hard-conditions/README.md | 2 +- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/subjects/devops/bin-status/README.md b/subjects/devops/bin-status/README.md index d84ea029..0e76a37a 100644 --- a/subjects/devops/bin-status/README.md +++ b/subjects/devops/bin-status/README.md @@ -7,9 +7,9 @@ Create the script `bin-status.sh` that will return the exit status of last comma - Expected output: ```console -$ true ; ./bin-status.sh +$ true ; source ./bin-status.sh 0 -$ false ; ./bin-status.sh +$ false ; source ./bin-status.sh 1 $ ``` @@ -27,5 +27,7 @@ $ random-binary ; echo $? $ ``` +The `source` command is used in Unix-like operating systems to execute commands from a specified file in the current shell environment. When the `source` command is used, the specified file is read by the shell and executed in the same environment as the caller, without creating a new subshell. + > You have to use Man or Google to know more about commands flags, in order to solve this exercise! -> Google and Man will be your friends! \ No newline at end of file +> Google and Man will be your friends! diff --git a/subjects/devops/calculator/README.md b/subjects/devops/calculator/README.md index 06660678..f8bebab9 100644 --- a/subjects/devops/calculator/README.md +++ b/subjects/devops/calculator/README.md @@ -8,6 +8,7 @@ In this exercise you will make a script `calculator.sh` that will take 3 argumen - The second argument will be the operator. Each operator should have its own function named as follow: + - `+`: `do_add()`. - `-`: `do_sub()`. - `*`: `do_mult()`. @@ -36,6 +37,7 @@ $ ### Error handling All errors will print a specific message on **stderr** (ending with a newline) and returns a specific non-zero value: + - Wrong number of arguments: `"Error: expect 3 arguments"`, returns `1`. - Division by 0: `"Error: division by 0"`, exit with `2`. - Invalid operator: `"Error: invalid operator"`, exit with `3`. @@ -46,25 +48,26 @@ All errors will print a specific message on **stderr** (ending with a newline) a ### Hints - `case` statement example: + ```sh # Check the first argument given to a script case $1 in "left") echo "We will turn left" ;; - + "right") echo "We will turn right" ;; - + "top") echo "We will turn top" ;; - + "bottom") echo "We will turn bottom" ;; - + # Any other case *) # This is printed in stderr @@ -75,7 +78,8 @@ esac ``` - Example of a function taking two arguments and returning a value by printing it. -The behavior of this function is the same than the one expected for the operators functions you will create: + The behavior of this function is the same than the one expected for the operators functions you will create: + ```sh print_full_name () { name=$1 @@ -86,11 +90,11 @@ print_full_name () { print_full_name "Gene" "Mallamar" ``` -> Google and Man will be your friends! +> Google and Man will be your friends! ### References -- [Bash functions](https://linuxize.com/post/bash-functions/) -- [Test if a variable is a number](https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash) -- [Print on standard error](https://stackoverflow.com/questions/2990414/echo-that-outputs-to-stderr) -- [Case statement](https://linuxize.com/post/bash-case-statement/) +- [Bash functions](https://linuxize.com/post/bash-functions/) +- [Test if a variable is a number](https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash) +- [Print on standard error](https://stackoverflow.com/questions/2990414/echo-that-outputs-to-stderr) +- [Case statement](https://linuxize.com/post/bash-case-statement/) diff --git a/subjects/devops/check-user/README.md b/subjects/devops/check-user/README.md index 1156c2eb..7cd4db7c 100644 --- a/subjects/devops/check-user/README.md +++ b/subjects/devops/check-user/README.md @@ -5,6 +5,7 @@ In this exercise you will make a script `check-user.sh` that will take 2 arguments and return information about the selected user, always ended by a new line. The first argument will be a flag defining the behavior of the script: + - `-e`: check if the user exists, returns `yes` or `no` appropriately. - `-i`: returns information about the user. @@ -30,10 +31,12 @@ $ ### Error handling All errors will print a specific message on **stderr** (ending with a newline) and returns a specific non-zero value: + - Wrong number of arguments: `"Error: expect 2 arguments"`, exit with `1`. - First argument different from `-e` or `-i`: `"Error: unknown flag"`, exit with `1`. ### Hints + - `getent` is a command to get entries from a database. `passwd` is the database where information about users is stored. - `getent passwd` will give you the list of all users. - `getent passwd ` will give you information about a specific user. @@ -42,4 +45,5 @@ All errors will print a specific message on **stderr** (ending with a newline) a > `man getent` will provide extensive documentation about this command. ### Resources -> [List Linux users](https://linuxize.com/post/how-to-list-users-in-linux/) + +> [List Linux users](https://linuxize.com/post/how-to-list-users-in-linux/) diff --git a/subjects/devops/custom-ls/README.md b/subjects/devops/custom-ls/README.md index 7c8c1865..7d5d6faa 100644 --- a/subjects/devops/custom-ls/README.md +++ b/subjects/devops/custom-ls/README.md @@ -5,11 +5,12 @@ Create the script `custom-ls.sh` which will create an alias `custom-ls`. The alias `custom-ls`: - - shows the file details in long list format. - - does not list group information. - - does not ignore entries starting with `.`. - - prints the allocated size of each file, in blocks. - - sorts by file size, largest first. + +- shows the file details in long list format. +- does not list group information. +- does not ignore entries starting with `.`. +- prints the allocated size of each file, in blocks. +- sorts by file size, largest first. Expected behavior: @@ -28,7 +29,7 @@ $ An alias is a shortcut that references a command. An alias replaces a string that invokes a command in the Linux shell with another user-defined string. -`alias` command instructs the shell to replace one string with another string while executing the commands. +`alias` command instructs the shell to replace one string with another string while executing the commands. ```console $ alias testcmd="echo 01school" @@ -45,17 +46,22 @@ $ To create and add aliases permanently to your bash shell on Linux and Unix-like systems: 1- Edit the `~/.bashrc`: + ```console vi ~/.bashrc # or # nano ~/.bashrc ``` + 2- Append your bash alias, For example append: + ```console alias testcmd="echo 01school" ``` + 3- Save and close the file. 4- Activate alias + ```console source ~/.bashrc ``` diff --git a/subjects/devops/hard-conditions/README.md b/subjects/devops/hard-conditions/README.md index b0702928..fff250e1 100644 --- a/subjects/devops/hard-conditions/README.md +++ b/subjects/devops/hard-conditions/README.md @@ -9,7 +9,7 @@ If it exists and it is executable you must print "File is executable" if it is n ```console $ ls -l --rw-rw-r-- 1 miguel miguel 19 dez 28 14:19 docs +-rw-rw-r-- 1 user user 19 dez 28 14:19 docs -rwxrwxr-x 1 user user 95 dez 29 15:48 example.sh $ ./hard-conditions.sh path/to/example.sh File is executable