diff --git a/Makefile b/Makefile index 48fecda..54393c0 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,13 @@ # By: qmennen +#+ # # +#+ # # Created: 2024/10/15 11:48:46 by whaffman #+# #+# # -# Updated: 2025/03/04 18:26:26 by whaffman ######## odam.nl # +# Updated: 2025/03/06 15:56:12 by whaffman ######## odam.nl # # # # **************************************************************************** # NAME = minishell -# FLAGS=-DNOCOLORS -DNOBANNER -DNOPROMPT -FLAGS=-DNOBANNER +FLAGS=-DNOCOLORS -DNOBANNER -DNOPROMPT -DSHELL_NAME=\"bash\" +# FLAGS=-DNOBANNER SRC_PATH = src INC_PATH = inc diff --git a/README.md b/README.md index e4e74f7..eeca4a3 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ A lot of amazing shell stuff - `cat $PWD/test` should expand, - `cd -` : `bash: cd: OLDPWD not set` - `cd ~` : does not expand ? + - ~ does expand in bash but not in any quotes +- `echo a '' b` = "a b" ipv "a b" ## Tester - [minishell_tester](https://github.com/LucasKuhn/minishell_tester) @@ -31,6 +33,42 @@ A lot of amazing shell stuff - [ ] CTRL+\ during `sleep 5` should do nothing, but returns a new prompt - [ ] echo "hello" > /root/protected.txt gives the error but still prints - [ ] cat < filenoexit returns `minishell: minishell: unable to write to temp file: No such file or directory` but we're not writin +- [x] Find absolute path for command input ('/', './', 'cmd') +- [x]Add heredoc to tokenizer +- [x] Environment to `t_list` +- [x] Get environment array (export) +- [x] Set environment variable (export) +- [x] Simple builtin export +- [x] builtins +- [x] Preliminary signals +- [x] Define struct for commands, something like ( + ```c + typedef struct s_command + { + char *command; + char *path; + char **args; + int fd_in; + int fd_out; + } t_command; + ``` +) +- [x] Make the `executor`, run a command +- [x] Make a parser to create a command list +- [x] Add redirects, appends, pipe etc. File descriptor functions + a command can have multiple redirects but only the last is used for stdout + Redirects take precedence over pipes, but pipes are still created and managed. + should it close the unused pipe-end? + all redirects are opened and closed, but only last fd is used. + multiple HEREDOCs can be nested, only last is used. +- [x] Expand \$ vars & support \$ ~? + * [x] $var + * [x] $? + * [ ] ~ +- [x] export without arguments +- [ ] ft_free_arr_safe in environment mess +- [x] builtins not first in pipeline? wtf is happening HAHAHAHAHAH its not using builtin, but core-utils +- CB command to change banner - __Bonus:__ Command tree for &&, ||, * ## Signals diff --git a/inc/minishell.h b/inc/minishell.h index e60db1e..47ae890 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -6,13 +6,17 @@ /* By: marvin +#+ */ /* +#+ */ /* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */ -/* Updated: 2025/03/02 22:12:12 by whaffman ######## odam.nl */ +/* Updated: 2025/03/06 15:55:50 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H +# ifndef SHELL_NAME +# define SHELL_NAME "minishell" +# endif // SHELL_NAME + # include "allowed.h" # include "libft.h" # include "typedef.h" diff --git a/src/utils/error_msg.c b/src/utils/error_msg.c index 4bab842..879e116 100644 --- a/src/utils/error_msg.c +++ b/src/utils/error_msg.c @@ -6,12 +6,11 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */ -/* Updated: 2025/03/03 21:20:09 by whaffman ######## odam.nl */ +/* Updated: 2025/03/06 15:36:30 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define SHELL_NAME "minishell" void error_msg(char *func, char *msg) { diff --git a/tests/test.sh b/tests/test.sh index 584a003..17ad827 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,17 +1,36 @@ #!/bin/bash -minishell_output=$(../minishell -c "$1") -minishell_exit_code=$? +compare_shells() { + minishell_output=$(../minishell -c "$1" 2>&1) + minishell_exit_code=$? -bash_output=$(bash -c "$1") -bash_exit_code=$? + bash_output=$(bash -c "$1" 2>&1 | sed 's/ line 1://g') + bash_exit_code=$? -paste <(echo -e "Minishell:\n$minishell_output") <(echo -e "Bash:\n$bash_output") | column -t -s $'\t' -echo "Minishell exit code: $minishell_exit_code" -echo "Bash exit code: $bash_exit_code" + echo -e "\e[33m$1\e[0m" + echo "===================================" -if [ $minishell_exit_code -eq $bash_exit_code ]; then - echo "Exit codes match." -else - echo "Exit codes do not match." -fi \ No newline at end of file + + if [ "$minishell_output" != "$bash_output" ]; then + paste <(echo -e "Minishell:\n$minishell_output" | cat -e) <(echo -e "Bash:\n$bash_output" | cat -e) | column -t -s $'\t' + else + echo -e "\e[32mstdout: Ok!\e[0m" + fi + + if [ $minishell_exit_code -ne $bash_exit_code ]; then + echo "Minishell exit code: $minishell_exit_code" + echo "Bash exit code: $bash_exit_code" + echo "Exit codes do not match." + else + echo -e "\e[32mexit code: Ok!\e[0m" + fi +} + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +while IFS= read -r line; do + compare_shells "$line" +done < "$1" \ No newline at end of file diff --git a/tests/test.txt b/tests/test.txt index 953f1da..7c4a70a 100644 --- a/tests/test.txt +++ b/tests/test.txt @@ -1,85 +1,6 @@ -cd -cd .. -cd . -cd /Users -cd // -cd '//' -cd ////// -cd ./././ -cd / -cd '/etc' -cd '/var' -cd "$PWD/prompt" -cd "doesntexist" -cd "doesntexist" 2>/dev/null -cd ../../.. -cd .. -cd .. -cd ? -cd + -cd _ -cd bark bark -cd '/' -cd $PWD/file_tests -cd $OLDPWD/builtins -echo -echo echo -eCho -eChO -eCHO -echo $ -echo $ $ -ECHO -echo rhobebou -echo stop barking -echo "bonjour" -echo bonjour -echo 'bonjour' -echo -n bonjour -echo -nn bonjour -echo -n -n -n bonjour -echo "-n" bonjour -echo -n"-n" bonjour -echo "-nnnn" bonjour -echo "-nnnn" -n bonjour -echo "-n -n -n"-n bonjour -echo "-n '-n'" bonjour -echo $USER -echo "$USER" -echo "'$USER'" -echo " '$USER' " -echo text"$USER" -echo text"'$USER'" ' $USER ' -echo "text" "$USER" "$USER" -echo ' $USER ' -echo text "$USER" "$USER"text -echo ''''''''''$USER'''''''''' -echo """"""""$USER"""""""" -echo $USER'$USER'text oui oui oui oui $USER oui $USER '' -echo $USER '' $USER $USER '' $USER '' $USER -n $USER -echo ' \' ' \' -echo '\" ' " \"\"" -echo \\\" \\\" \\\" \\\"\\\"\\\" \\\'\\\'\\\' -echo "$USER""$USER""$USER" -echo text"$USER"test -echo '$USER' "$USER" "text \' text" -echo '$USER' -echo $USER " " -echo "$USER""Users/$USER/file""'$USER'"'$USER' -echo "$USER$USER$USER" -echo '$USER'"$USER"'$USER' -echo '"$USER"''$USER'"""$USER" -echo " $USER "'$PWD' -echo " $USER \$ "'$PWD' -echo $USER=4 -echo $USER=thallard -echo $USER -echo $? -echo $PWD/file -echo "$PWD/file" -echo "text" "text$USER" ... "$USER" -echo $PWD + + env | grep "_=" env | grep "_=" env | grep "SHLVL" @@ -111,66 +32,7 @@ ls -la > tmp/file ls -la > tmp/file unset export TEST=100 -unset doesntexist -unset PWD -unset PWD -unset OLDPWD -unset PATH -unset PATH -unset PATH -unset TES\\\\T -unset TES;T -unset TES.T -unset TES+T -unset TES=T -unset TES}T -unset TES{T -unset TES-T -unset -TEST -unset _TEST -unset TES_T -unset TEST_ -unset TE*ST -unset TES#T -unset TES@T -unset TES!T -unset TES$?T -unset ============ -unset +++++++ -unset ________ -unset export -unset echo -unset pwd -unset cd -unset unset -unset sudo -unset TES^T -unset TES!T -unset TES\~T -echo $PWD -echo $PWD|cat -e -echo $PWD hallo | cat -e -echo '$PWD hallo | cat -e' -echo "$PWD hallo | cat -e" -wc < Makefile -l | cat -e > outfile | echo hello | rev > outfile2 -< test.txt < Makefile out | < README.md cat -e -< README.md cat -e | out1 | < in2 cat -env | rev | head -5 | cat -e | rev -< in1 out > out2 > out3 >> out4 -echo ok"hello"ok1"mfg" == echo ok'hello'ok1'mfg' -echo okhellook1"mfg" == echo okhellook1'mfg' -echo "o""k "hellook1 == echo 'o''k 'hellook1 -echo '"***hello***"' -echo "'***hello***'" -echo ok"'hello'"ok1"hello1"ok2 -echo "text" "$USER" "$USER" -echo """"""""$USER"""""""" -echo "-n -n -n"-n bonjour -echo "'$USER'" -echo "$PWD "a -echo " $PWD" + + exit diff --git a/tests/test_cd.txt b/tests/test_cd.txt new file mode 100644 index 0000000..a38a482 --- /dev/null +++ b/tests/test_cd.txt @@ -0,0 +1,25 @@ +cd ; pwd +cd .. ; pwd +cd . ; pwd +cd /Users ; pwd +cd // ; pwd +cd '//' ; pwd +cd ////// ; pwd +cd ./././ ; pwd +cd / ; pwd +cd '/etc' ; pwd +cd '/var' ; pwd +cd "$PWD/prompt" ; pwd +cd "doesntexist" ; pwd +cd "doesntexist" 2>/dev/null ; pwd +cd ../../.. ; pwd +cd .. ; pwd +cd .. ; pwd +cd ? ; pwd +cd + ; pwd +cd _ ; pwd +cd bark bark ; pwd +cd '/' ; pwd +cd $PWD/file_tests ; pwd +cd $OLDPWD/builtins ; pwd +cd ~ ; pwd \ No newline at end of file diff --git a/tests/test_echo.txt b/tests/test_echo.txt new file mode 100644 index 0000000..40fb2f9 --- /dev/null +++ b/tests/test_echo.txt @@ -0,0 +1,81 @@ +echo +echo echo +eCho +eChO +eCHO +echo $ +echo $ $ +ECHO +echo rhobebou +echo stop barking +echo "bonjour" +echo bonjour +echo 'bonjour' +echo -n bonjour +echo -nn bonjour +echo -n -n -n bonjour +echo "-n" bonjour +echo -n"-n" bonjour +echo "-nnnn" bonjour +echo "-nnnn" -n bonjour +echo "-n -n -n"-n bonjour +echo "-n '-n'" bonjour +echo $USER +echo "$USER" +echo "'$USER'" +echo " '$USER' " +echo text"$USER" +echo text"'$USER'" ' $USER ' +echo "text" "$USER" "$USER" +echo ' $USER ' +echo text "$USER" "$USER"text +echo ''''''''''$USER'''''''''' +echo """"""""$USER"""""""" +echo $USER'$USER'text oui oui oui oui $USER oui $USER '' +echo $USER '' $USER $USER '' $USER '' $USER -n $USER +echo ' \' ' \' +echo '\" ' " \"\"" +echo \\\" \\\" \\\" \\\"\\\"\\\" \\\'\\\'\\\' +echo "$USER""$USER""$USER" +echo text"$USER"test +echo '$USER' "$USER" "text \' text" +echo '$USER' +echo $USER " " +echo "$USER""Users/$USER/file""'$USER'"'$USER' +echo "$USER$USER$USER" +echo '$USER'"$USER"'$USER' +echo '"$USER"''$USER'"""$USER" +echo " $USER "'$PWD' +echo " $USER \$ "'$PWD' +echo $USER=4 +echo $USER=thallard +echo $USER +echo $? +echo $PWD/file +echo "$PWD/file" +echo "text" "text$USER" ... "$USER" +echo $PWD +echo $PWD|cat -e +echo $PWD hallo | cat -e +echo '$PWD hallo | cat -e' +echo "$PWD hallo | cat -e" +wc < Makefile -l | cat -e > outfile | echo hello | rev > outfile2 +< test.txt < Makefile out | < README.md cat -e +< README.md cat -e | out1 | < in2 cat +env | rev | head -5 | cat -e | rev +< in1 out > out2 > out3 >> out4 +echo ok"hello"ok1"mfg" == echo ok'hello'ok1'mfg' +echo okhellook1"mfg" == echo okhellook1'mfg' +echo "o""k "hellook1 == echo 'o''k 'hellook1 +echo '"***hello***"' +echo "'***hello***'" +echo ok"'hello'"ok1"hello1"ok2 +echo "text" "$USER" "$USER" +echo """"""""$USER"""""""" +echo "-n -n -n"-n bonjour +echo "'$USER'" +echo "$PWD "a +echo " $PWD" \ No newline at end of file diff --git a/tests/test_env.txt b/tests/test_env.txt new file mode 100644 index 0000000..2c9f94f --- /dev/null +++ b/tests/test_env.txt @@ -0,0 +1,3 @@ +env | grep "_=" +env | grep "_=" +env | grep "SHLVL" \ No newline at end of file diff --git a/tests/test_exit.txt b/tests/test_exit.txt deleted file mode 100644 index 39e3906..0000000 --- a/tests/test_exit.txt +++ /dev/null @@ -1,2 +0,0 @@ -echo "yeah" -exit diff --git a/tests/export_test.txt b/tests/test_export.txt similarity index 100% rename from tests/export_test.txt rename to tests/test_export.txt diff --git a/tests/test_unset.txt b/tests/test_unset.txt new file mode 100644 index 0000000..679c0c1 --- /dev/null +++ b/tests/test_unset.txt @@ -0,0 +1,36 @@ +unset doesntexist +unset PWD +unset PWD +unset OLDPWD +unset PATH +unset PATH +unset PATH +unset TES\\\\T +unset TES;T +unset TES.T +unset TES+T +unset TES=T +unset TES}T +unset TES{T +unset TES-T +unset -TEST +unset _TEST +unset TES_T +unset TEST_ +unset TE*ST +unset TES#T +unset TES@T +unset TES!T +unset TES$?T +unset ============ +unset +++++++ +unset ________ +unset export +unset echo +unset pwd +unset cd +unset unset +unset sudo +unset TES^T +unset TES!T +unset TES\~T \ No newline at end of file