D-Daria / minishell

Shell implementation (group project)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mrhyhorn and sshield group 👩🏻‍💻 🧑🏻‍💻 at School21

📄 Summary

The aim of this project is to implement our own shell with limited functionality (it's mini). It allows to get better understanding of UNIX command-line interpreter.

📝 Project description

Requirements

The shell should:

  • Display a prompt when waiting for a new command.

  • Have a working history.

  • Search and launch the right executable (based on the PATH variable or using a relative or an absolute path).

  • Not use more than one global variable. Think about it. You will have to explain its purpose.

  • Not interpret unclosed quotes or special characters which are not required by the subject such as \ (backslash) or ; (semicolon).

  • Handle (single quote) which should prevent the shell from interpreting the metacharacters in the quoted sequence.

  • Handle " (double quote) which should prevent the shell from interpreting the metacharacters in the quoted sequence except for $ (dollar sign).

  • Implement redirections:

    • < should redirect input.
    • > should redirect output.
    • << should be given a delimiter, then read the input until a line containing the delimiter is seen.
    • >> should redirect output in append mode.
  • Implement pipes (| character). The output of each command in the pipeline is connected to the input of the next command via a pipe.

  • Handle environment variables ($ followed by a sequence of characters) which should expand to their values.

  • Handle $? which should expand to the exit status of the most recently executed foreground pipeline.

  • Handle ctrl-C, ctrl-D and ctrl-\ which should behave like in bash.

  • In interactive mode:

    • ctrl-C displays a new prompt on a new line.
    • ctrl-D exits the shell.
    • ctrl-\ does nothing.
  • Your shell must implement the following builtins:

    • echo with option -n
    • cd with only a relative or absolute path
    • pwd with no options
    • export with no options
    • unset with no options
    • env with no options or arguments
    • exit with no options

🏁 How to run

The program can be compiled on both MacOS and Linux.

make
./minishell

or

make && ./minishell

🛠 Tests

• Signals

After pressing CTRL-C echo $? should display exit status 1

• Check fd’s leaks / проверить незакрытые fd (файловые дескрипторы)

ls -l /proc/<pid>/fd

lsof -p <pid>
#or
lsof -c <executable>

• Redirections

ls -l -a -p > file > file2 > file3

# redirections can precede or follow the command
< file1 < file2 wc -l < file3 > outfile >> outfile1 >> outfile2

# wc should read from last heredoc end3
cat -e << lim | wc -l << end < infile << end2 < infile1 << end3

# out2 shouldn't be created
cat -e > out > out1 > no_permission > out2

• Pipes

ls -l -a -p | awk '{print $1}' | cat -e

cat /dev/random | head -c 100 | wc -c

yes | head -c 100 | cat -e > out

time -p sleep 3 | echo toto
many pipes
echo test | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e | cat -e| cat -e| cat -e| cat -e| cat -e| cat -e| cat -e| cat -e| cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e|cat -e > out

• Echo

[minishell]->  echo -nnnnnnnnnnn -n -n -n -n -n -n -n -nnnnnnnl TOTO
-nnnnnnnl TOTO[minishell]->

[minishell]-> $? + $?
minishell: 0: command not found
[minishell]-> echo $? + $?
127 + 127

• cd

[minishell]-> export HOME="MY_HOME"
[minishell]-> export
declare -x COLORFGBG="15;0"
declare -x COLORTERM="truecolor"
declare -x HOME="MY_HOME"
[minishell]-> cd ~
bash: cd: MY_HOME: No such file or directory

About

Shell implementation (group project)


Languages

Language:C 97.4%Language:Makefile 2.6%