minishell's People
minishell's Issues
exit builtin with one or more arguments
exit builtin
Accept one argument or no arguments.
Exits with exit status 0 when executed without arguments.
Exits with the argument passed as exit status if the argument is valid.
Prints an error if the argument is non-numeric or if it exceds the LLONG_MIN or LLONG_MAX (-9223372036854775808 or 9223372036854775807 on 64-bit machine).
Also prints an error if there are more than one arguments.
Example output of exit test
:
exit
bash: exit: test: numeric argument required
exits with exit status 2
Example output of exit 9223372036854775808
(64-bit)
exit
bash: exit: 9223372036854775808: numeric argument required
exits with exit status 2
Example output of exit a b c
exit
bash: exit: a: numeric argument required
exits with exit status 2 and prints an error only for the first argument
Example output of exit 1 a
exit
bash: exit: too many arguments
Does not exit in this case, instead it returns and set the last exit status of the command to 1
When there are multiple arguments:
If the first argument is not a valid format it exits with exit status 2 and prints the argument and numeric argument required
If the first argument is a valid argument it doen't exit but instead returns 1, sets the last exit status to 1 and prints too many arguments
Multiple semicolon tokens error
If after semicolon ;
token there is another semicolon ;
token bash prints:
bash: syntax error near unexpected token `;;'
Currently, our shell prints only one semicolon:
minishell: syntax error near unexpected token `;'
Control+C after cat
After cat without any arguments, if you press ctrl-C, bash shows:
user42@salty-VirtualBox:~/github/minishell$ cat ^C user42@salty-VirtualBox:~/github/minishell$
And our minishell:
minishell> cat ^Cminishell>
A new line is missing
Fix echo with multiples -n flag
Fix echo when there are multiple -n flags or -nnnnnnn
Multiple redirections of the same type
Example:
cat some_file > first_file > second_file > third_file
bash will create first_file and second_file and will save the output of cat
in the third_file
Currently, our minishell prints an error and set last command exit status to 2
Syntax error after failed input redirection followed by a semicolon
Example:
< notafile ; echo $?
Bash output:
bash: notafile: No such file or directory
1
Minishell output:
minishell: notafile: No such file or directory
minishell: syntax error near unexpected token `;'
2
Set underscore _ environment variable before executing each command in a pipeline and unset after pipeline
After some testing i think bash is setting the $_
variable before executing each command in pipeline then after the pipeline unsets it.
Example:
/usr/bin/env | sort | cat -ev
echo $_
ls | /usr/bin/env | sort
echo $_
In the pipeline the $_
variable is set but after the pipeline it's unset
Currently, our shell unsets the $_
variable before executing the pipeline and doesn't set it before executing a command, inside the pipeline.
To fix it we could set the $_
variable in fork()
before executing a command in the pipeline.
Set PWD when initializing the shell
Expected:
PWD
environment variable should be initialized when starting the shell
Actual:
PWD
environment variable is not initialized when starting the shell
Currently we're initializing the env variables to the value that are stored in environ
bash is setting PWD
at start
How to test/ Example:
usr/bin/env -i TERM="xterm-256color" PATH="$PATH" bash --norc; echo $PWD
This command will start a new bash shell with only two environment variable TERM and PATH then print the value of PWD
usr/bin/env -i TERM="xterm-256color" PATH="$PATH" ./minishell; echo $PWD
This command will start a new minishell shell with only two environment variable TERM and PATH then print the value of PWD
Variable expansion should happen just before executing the command
Currently we do variable expansion ($?
, $PWD
, etc) when parsing the tokens and creating the commands.
So commands like in the example below have different output in our minishell than bash
unset TEST
export TEST=test; echo $TEST
One solution is to modify word_expansion()
and move it from parse()
function to the do_cmd()
and do_pipeline()
Execute command with empty PATH or a path that has ':' at the start or end
There is an error when the PATH variable is an empty string "" or it has a ":" character at the start or the end of the string.
Bash will search in the current directory in this cases.
Currently our minishell returns an error.
Example:
echo -e '#!/bin/sh\necho bonjour' > somecmd
chmod +x somecmd
export PATH=''
somecmd ; echo $?
Bash output
bonjour
0
Minishell output:
minishell: somecmd: No such file or directory
127
Return from main with the exit status of the last command
After finishing the main loop, return the exit status of the last command.
Example:
non_existant_command
Ctrl-D
echo $?
in parent shell
It should print 127
Incorrect exit status and error message after executing a command that is in PATH and execve fails
Example:
mkdir path
cp /usr/bin/which ./path/a
chmod 000 ./path/a
path/a
Bash output:
bash: path/a: Permission denied
126
Minishell output:
minishell: path/a: No such file or directory
127
Remove quotes from environment variable only once
Currently were removing the quotes of the environment variable twice, once when exporting the env then again when printing it.
Example:
export TEST=’\hello\\w\\\\orld’ ; echo $TEST
Expected output:
’hello\w\\orld’
Actual output:
’hellow\orld’
SHLVL with a value that overflow a LONG_MAX/LONG_MIN
Currently if the SHLVL is less than LONG_MIN or more than LONG_MAX our minishell is setting it to 0, bash is setting it to 1.
Example:
export SHLVL='18446744073709551615'
./minishell
echo $SHLVL
export SHLVL='-9223372036854775809'
./minishell
echo $SHLVL
Expected:
1
1
Current:
0
0
To fix it we could extract exit_atoll()
function from msh_exit.c into a separate file and rename + use it for this feature too since it deals with long
int overflows.
Skip spaces at the start of exit builtin
bash skips and ignores spaces at the start of exit argument
Examples:
bash
bash
exit ' 10'
echo $?
Outputs
exit
10
Our minishell
./minishell
exit ' 10'
echo $?
Outputs:
exit
minishell: exit: 10: numeric argument required
2
Command not found output
When a command is not found, bash show the following:
user42@salty-VirtualBox:/github/minishell$ notacommand/github/minishell$
notacommand: command not found
user42@salty-VirtualBox:
And our minishell shows:
minishell> anycommand
minishell: anycommand: Success
minishell>
cd builtin exits the program if PWD is not set
Example:
unset PWD
cd
Expected:
To change directory to the home directory
Actual:
Print Error: Success
and exits with exit status 1.
Segfault when executing an empty environment variable
Example:
unset TEST
$TEST
Printing underscore _ environment variable after an export
After exporting an environment variable and printing $_
bash prints only the name of the env variable
Example:
export TEST=test ; echo $_
Outputs:
TEST
Currently, our shell outputs both the name and the value.
TEST=test
To fix it we could set $_ in export builtin, after evaluating the env name.
Backslash removal inside double quote when next character is $
Backslash character should be removed inside double quotes if the next character is $
Example:
echo "\$"
echo "\$TEST"
Should print
$
$TEST
Currently is printing
\$
\$TEST
Executing a command that it's not in path but it is in the current directory
Currently our shell is executing commands that are not in path if a file with the same name is in the current working directory
Example:
From the directory with minishell binary (the root of the repository)
minishell
Expected
minishell: command not found
Actual:
minishell is executed and a new shell is created
Skip spaces at the start of SHLVL
bash skips and ignores spaces at the start of SHLVL
Examples:
bash
export SHLVL=' 10'
bash
echo $SHLVL
Outputs 11
Our minishell
export SHLVL=' 10'
./minishell
echo $SHLVL
Outputs 1
exit without arguments after a failed command
Currently, executing exit
after a command that failed will exit from the program with exit status 0 instead of the exit status of the last command.
Example:
not_a_command
exit
Then in the parent shell
echo $?
Our minishell prints 0
and bash prints 127
Executing a file with missing exec format
When executing a file that doesn't have a correct executable format bash does nothing and sets exit status to 0.
execve returns ENOEXEC 8 Exec format error
in this case so i think we can use this.
Example:
bash
echo > testfile ; chmod +x testfile ; ./testfile
echo $?
Output:
0
./minishell
echo > testfile ; chmod +x testfile ; ./testfile
echo $?
Output:
minishell: ./testfile: Exec format error
127
If there is a redirection error in the middle of a pipeline, execute only the commands after that command
Currently if there is a redirection error in the middle of a pipeline we ignore that command and pipe the output of the previous to the input of the next. Bash will execute only the commands that are after the last command that had a redirection error.
Example:
echo ok | cat < notafile | cat -ev
Expected output:
bash: notafile: No such file or directory
Current output:
minishell: notafile: No such file or directory
ok$
We could fix this at the same time when we fix #92 because they are related.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.