Shell 01
Shell 01
Shell 01
Summary: This document is the subject for the module Shell 01 of the C Piscine @ 42.
Version: 7.5
Contents
I Instructions 2
II Foreword 3
1
Chapter I
Instructions
• These exercises are carefully laid out by order of difficulty - from easiest to hardest.
We will not take into account a successfully completed harder exercise if an easier
one is not perfectly functional.
• Make sure you have the appropriate permissions on your files and directories.
• On top of that, your exercises will be checked and graded by a program called
Moulinette.
• Moulinette is very meticulous and strict in its evaluation of your work. It is entirely
automated and there is no way to negotiate with it. So if you want to avoid bad
surprises, be as thorough as possible.
• You cannot leave any additional file in your directory than those specified in the
subject.
• Got a question? Ask your peer on the right. Otherwise, try your peer on the left.
• Check out the "C Piscine" part of the forum on the intranet.
• Examine the examples thoroughly. They could very well call for details that are
not explicitly mentioned in the subject...
2
Chapter II
Foreword
The European otter (Lutra lutra), also known as the Eurasian otter, Eurasian
river otter, common otter and Old World otter, is a European and Asian member
of the Lutrinae or otter subfamily, and is typical of freshwater otters.
The European otter is a typical species of the otter subfamily. Brown above
and cream below, these long, slender creatures are well-equipped for their
aquatic habits. Its bones show osteosclerosis, increasing their density to
reduce buoyancy.
This otter differs from the North American river otter by its shorter neck,
broader visage, the greater space between the ears and its longer tail.
However, the European otter is the only otter in its range, so it cannot be
confused for any other animal. Normally, this species is 57 to 95 cm (23–37 in)
long, not counting a tail of 35–45 cm (14–18 in).
The female is shorter than the male.
The European otter is the most widely distributed otter species, its range
including parts of Asia and Africa, as well as being spread across Europe.
Though currently believed to be extinct in Liechtenstein, and Switzerland,
they are now very common in Latvia, along the coast of Norway and across
Great Britain, especially Shetland, where 12% of the UK breeding population
exist. Ireland has the highest density of Eurasian otters in Europe.
In Italy, they can be found in southern parts of the peninsula.
The South Korean population is endangered.
3
Chapter III
Exercise : 00
Exam
• During the week, you will be able to sign up for Friday’s exam in the agenda, don’t
forget.
• Make sure you’ve registered for the exam (the event AND the project !).
• Make sure you’ve made sure you’ve registered for the exam (the event AND the
project ! Yep, both !).
4
Chapter IV
Exercise 01
print_groups.sh
Turn-in directory : ex01/
Files to turn in : print_groups.sh
Allowed functions : None
• Write a command line that will display the list of groups for which the login,
contained in the environment variable FT_USER , is a member. Separated by
commas without spaces.
• Examples :
◦ for FT_USER=nours, the result is "god,root,admin,master,nours,bocal" (with-
out quotation marks)
$>./print_groups.sh
god,root,admin,master,nours,bocal$>
man id
5
Chapter V
Exercise 02
find_sh.sh
Turn-in directory : ex02/
Files to turn in : find_sh.sh
Allowed functions : None
• Write a command line that searches for all file names that end with ".sh" (without
quotation marks) in the current directory and all its sub-directories. It should
display only the file names without the .sh.
• Example of output :
$>./find_sh.sh | cat -e
find_sh$
file1$
file2$
file3$
$>
6
Chapter VI
Exercise 03
count_files.sh
Turn-in directory : ex03/
Files to turn in : count_files.sh
Allowed functions : None
• Write a command line that counts and displays the number of regular files and
directories in the current directory and all its sub-directories. It should include ".",
the starting directory.
• Example of output :
$>./count_files.sh | cat -e
42$
$>
7
Chapter VII
Exercise 04
MAC.sh
Turn-in directory : ex04/
Files to turn in : MAC.sh
Allowed functions : None
• Write a command line that displays your machine’s MAC addresses. Each address
must be followed by a line break.
man ifconfig
8
Chapter VIII
Exercise 05
"\?$*'MaRViN'*$?\"
• Example :
9
C Piscine Shell 01
It’s up to you to decide if you want to continue with the following optional exercises
or switch to your next project. Both paths will make you see useful elements one day or
another.
• The very first exam is about C programming. So you may have already experienced
the very first C project before. Same for the rush at the end of the week (you’ll
learn soon about the rush).
• Your excellence in this Piscine will be evaluated on multiple factors. The completion
of each project is one of them, but the overall progress through the entire list of
projects of the Piscine is another. Choose wisely to optimize your results.
• It will always be possible to try the same project again in a couple of days/weeks,
until the end of the Piscine.
10
Chapter IX
Exercise 06
skip.sh
Turn-in directory : ex06/
Files to turn in : skip.sh
Allowed functions : None
• Write a command line that displays one line out of two for the command ls -l,
starting from the first line.
• Example of output :
$>ls -l | cat -e
total 4$
-rw-rw-r-- 1 eagle eagle ** ** 15 15:46 skip.sh$
-rw-rw-r-- 1 eagle eagle ** ** 15 15:41 tata$
-rw-rw-r-- 1 eagle eagle ** ** 15 15:41 titi$
-rw-rw-r-- 1 eagle eagle ** ** 15 15:41 toto$
-rw-rw-r-- 1 eagle eagle ** ** 15 15:41 tutu$
$>
$>./skip.sh | cat -e
total 4$
-rw-rw-r-- 1 eagle eagle ** ** 15 15:41 tata$
-rw-rw-r-- 1 eagle eagle ** ** 15 15:41 toto$
$>
11
Chapter X
Exercise 07
r_dwssap.sh
Turn-in directory : ex07/
Files to turn in : r_dwssap.sh
Allowed functions : None
• Write a command line that displays the output of a cat /etc/passwd command,
removing comments, every other line starting from the second line, reversing each lo-
gin, sorted in reverse alphabetical order, and keeping only logins between FT_LINE1
and FT_LINE2 included, and they must separated by ", " (without quotation
marks), and the output must end with a ".".
• Example: Between lines 7 and 15, the result should be something like this :
$> ./r_dwssap.sh
sstq_, sorebrek_brk_, soibten_, sergtsop_, scodved_, rlaxcm_, rgmecived_, revreswodniw_, revressta_
.$>
12
Chapter XI
Exercise 08
add_chelou.sh
Turn-in directory : ex08/
Files to turn in : add_chelou.sh
Allowed functions : None
• Write a command line that takes numbers from variables FT_NBR1, in ’\"?! base,
and FT_NBR2, in mrdoc base, and displays the sum of both in gtaio luSnemf base.
◦ Example 1:
FT_NBR1=\'?"\"'\
FT_NBR2=rcrdmddd
◦ The sum is :
Salut
◦ Example 2 :
FT_NBR1=\"\"!\"\"!\"\"!\"\"!\"\"!\"\"
FT_NBR2=dcrcmcmooododmrrrmorcmcrmomo
◦ The sum is :
Segmentation fault
13
Chapter XII
Turn in your assignment in your Git repository as usual. Only the work inside your repos-
itory will be evaluated during the defense. Don’t hesitate to double check the names of
your files to ensure they are correct.
You need to return only the files requested by the subject of this
project.
14