mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Michele Sessa
b7197ba49c
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
Check User
Instructions
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, returnsyes
orno
appropriately.-i
: returns information about the user.
The second argument will be the name of the checked user.
The information about the user will be formatted in the same way it appears in
/etc/passwd
.
Usage
$ ./check-user.sh -e root
yes
$ ./check-user.sh -i root
root:x:0:0:root:/root:/bin/bash
$ ./check-user.sh -e unknown
no
$ ./check-user.sh -i unknown
$
Your results may appear slightly different.
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"
, returns1
. - First argument different from
-e
or-i
:"Error: unknown flag"
, exit with1
.
Hints
man getent
will be a great resource to explore
List Linux users