Skip to content

Commit

Permalink
Works for first line in test_command.txt, but echoes the command agai…
Browse files Browse the repository at this point in the history
…n for the subsequent lines
  • Loading branch information
Jean Teissier authored and Jean Teissier committed Jul 29, 2024
1 parent 96d60b5 commit a4f81bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 11 additions & 7 deletions shell_buster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@ TEMP_DIR="./shell_comparison"
mkdir -p "$TEMP_DIR"

coproc MINISHELL { "$MINISHELL_PATH"; }
sleep 1

while IFS= read -r cmd
do
echo "Testing command: $cmd"

bash -c "$cmd" > "$TEMP_DIR/bash_output" 2> "$TEMP_DIR/bash_error"

echo Coproc_ID $MINISHELL_PID
echo Parent_ID $$
echo "$cmd" >&${MINISHELL[1]}
echo >&${MINISHELL[1]}
sleep 0.5

read -r echoed_cmd <&${MINISHELL[0]}
sleep 0.5

read -r output <&${MINISHELL[0]}
echo "$output" > "$TEMP_DIR/minishell_output"

echo "Bash output:"
cat "$TEMP_DIR/bash_output"
echo "Minishell output:"
cat "$TEMP_DIR/minishell_output"
if ! diff -q "$TEMP_DIR/bash_output" "$TEMP_DIR/minishell_output" >/dev/null
then
echo "Difference in stdout for command: $cmd"
echo "Bash output:"
cat "$TEMP_DIR/bash_output"
echo "Minishell output:"
cat "$TEMP_DIR/minishell_output"
echo "Diff:"
diff "$TEMP_DIR/bash_output" "$TEMP_DIR/minishell_output"
echo
Expand Down
3 changes: 2 additions & 1 deletion test_commands.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
echo Hello World
echo "HELLO WORLD"
echo Hello World What

0 comments on commit a4f81bd

Please sign in to comment.