Browse Source

docs(bin-status): fix the usage of bin status

format readmes of other exercises
pull/1936/head
miguel 1 year ago committed by MSilva95
parent
commit
768f97e4a4
  1. 8
      subjects/devops/bin-status/README.md
  2. 24
      subjects/devops/calculator/README.md
  3. 6
      subjects/devops/check-user/README.md
  4. 18
      subjects/devops/custom-ls/README.md
  5. 2
      subjects/devops/hard-conditions/README.md

8
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!
> Google and Man will be your friends!

24
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/)

6
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 <username>` 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/)

18
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
```

2
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

Loading…
Cancel
Save