@ -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/)
> [List Linux users](https://linuxize.com/post/how-to-list-users-in-linux/)
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: