@ -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!
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/)