YeGoRenji / minishell-1337

This is My minishell project for 42 Network school Cursus 1337
10 stars 0 forks source link

wrong error / return status in some error cases #4

Closed 0x00Jeff closed 1 year ago

0x00Jeff commented 1 year ago

hello, there is a case related to 3 errors when executing a command

executing a directory command in the current directory

the first one is when u execute a command that has the same name of a directory in the current directory

(15:58:42) [ afatimi@e3r8p18 | ~/git/1337/minishell-1337 ] (main)
$ ls
Makefile          compile_flags.txt include           minishell         src               watcher.sh
TODO              grammar-bash.txt  lol.png           nbr_args.sh       tree.dot          zbi
clean_push.sh     grammar.txt       main.c            objs              watcher-mac.sh
(15:58:42) [ afatimi@e3r8p18 | ~/git/1337/minishell-1337 ] (main)
$ include/
bash: include/: is a directory
(15:58:45) [ afatimi@e3r8p18 | ~/git/1337/minishell-1337 ] (main)
$ echo $?
126

note the previous examples in bash, the current dir has a directory called include, and when I tried to execute the command include it gave me include/: is a directory and returned the status 126

and this the behavior in our shell69 in the same directory

[/Users/afatimi/git/1337/minishell-1337]
➤ include
shell69: include: command not found
[/Users/afatimi/git/1337/minishell-1337]
➤ echo $?
127

needed changed:

executing a non-existent command : directory case

let's take an example with ls, its full path is /bin/ls, so when u try to execute some garbage command such as /bin/ls/wdswsws, it should fail with the error `/bin/ls/wdswsws not a directory`, shell69 does this just alright, but it fails to set the correct return status, we return 255 (-1), which we should return 126, here's how to replicate the issue

bash output:

$ /bin/ls/wdswsws
/bin/ls/wdswsws: Not a directory
(16:08:53) [ afatimi@e3r8p18 | ~/git/1337/minishell-1337 ] (main)
$ echo $?
126

our output

[/Users/afatimi/git/1337/minishell-1337]
➤ /bin/ls/wdswsws
shell69: /bin/ls/wdswsws: Not a directory
[/Users/afatimi/git/1337/minishell-1337]
➤ echo $?
255

executing a non-existent command : file case

when executing a command doesn't exists such as /de/fr/s/ws/cr/cr/ (randomness), bash exists with 127, we exist with 255 (-1)

0x00Jeff commented 1 year ago

fixed first problem in commit f652c6b

0x00Jeff commented 1 year ago

fixed second and third problem commit cd56b1a

0x00Jeff commented 1 year ago

@YeGoRenji please do review the changes in the commits, and do some tests then close this issue