Skip to content

titouanck/42-Minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

Build and launch the project

make && ./minishell

Makefile rules

image

Reference Shell

GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
bash --posix

Troubleshoot dependencies

sudo apt-get install libreadline-dev

Other details

  • Local variables have been implemented

  • To ensure efficient memory management, dynamically allocated memory is manually freed despite the presence of a garbage collector that only frees all memory at once in case of an unexpected program exit.

  • You can execute a command directly by using the "-c" option

./minishell -c [cmd]
  • In order to closely mimic the behavior of bash, the signal handling in Minishell changes when launched with a redirect.
if (!isatty(STDIN_FILENO) || !isatty(STDERR_FILENO))
  // Different signal behavior
  // See : srcs/signals

Relevant tests
Search and launch the right executable (based on the PATH variable or using a relative or an absolute path)
ls
.ls
/ls
ls -la
/tmp
/usr/bin/ls
cp /usr/bin/ls ./lsCopylsCopy./lsCopy
Handle single quote and double quote
echo '$PWD'
echo "$PWD"
echo '$''PW'D''
echo $PW''D''
echo ' << (not 'a' here-doc) > (nothing) ""<"" (nothing) >> (nothing)'
Implement redirection
cat < Makefile > out.txtcat out.txt
cat < Makefile > out.txtcat < Makefile >> out.txtcat out.txt
cat < thisFileDoesNotExist > out.txt
touch noRights.txtchmod 000 noRights.txtcat < noRights.txt
ls > $thisVariableDoesNotExist
< < > >>
>> < < <
<<
>>
>
<
Implement heredoc
< Makefile << limiter
cat << limiter < Makefile
cat << limiter1 << limiter2
echo << limiter
cat << limiter $PATH (inside the heredoc)
cat << "limiter"$PATH (inside the heredoc)
cat << 'limiter'$PATH (inside the heredoc)
Implement pipes
cat | cat | ls
| ls | ls
ls | ls |
ls ||| ls
sleep 2 | ls
cat /dev/urandom | head -n 5
printf "42\n" | cat | printf "4 8 15 16 23 42\n" | cat
Handle environment variables and $?
ls -wErrorecho $?
thisCommandDoesNotExistecho $?
echo $PATHecho $?
$SHELL
Your shell must implement some builtins
https://github.com/thallard/minishell_tester

On this project, my teammate and I agreed that we would each make a Minishell. Here is my version.