- Basic command execution
- I/O redirection (
<,>,>>) - Command piping (
|) - Multiple commands (
;) - Logical operators (
&&) - Command history
- Signal handling
gcc -o shell shell.c./shell# Test simple commands
ls
pwd
echo "Hello World"
# Test built-in commands
cd /tmp
pwd
cd ~
pwd# Input redirection
cat < /etc/passwd
# Output redirection
ls -la > output.txt
cat output.txt
# Output redirection with append
echo "First line" > append_test.txt
echo "Second line" >> append_test.txt
cat append_test.txt # Should show both lines# Simple pipe
ls -la | grep ".txt"
# Multiple pipes
cat /etc/passwd | grep "root" | wc -l
# Complex piping
ls -la | grep "." | sort -r | head -n 3# Execute multiple commands in sequence
echo "Testing" ; ls ; pwd# Second command runs only if first succeeds
ls && echo "ls succeeded"
ls /nonexistent && echo "This won't print"
# Chain multiple commands with &&
mkdir test_dir && cd test_dir && pwd && cd .. && rm -r test_dir# Run several commands, then:
history# Start a long-running command and press CTRL+C
sleep 10
# Press CTRL+C while it's running
# Verify the shell is still running by executing another command
echo "Shell is still alive"# Redirection with pipes
ls -la | grep ".txt" > text_files.txt
# Multiple commands with different features
echo "Testing" > test.txt ; cat test.txt | grep "Test" && echo "Found it!"
# Complex test case
find / -name "*.txt" 2>/dev/null | grep "etc" | sort | head -n 5 > result.txt && cat result.txtcd [directory]: Change current directoryhistory: Show command historyexit: Exit the shell
The shell provides error messages for:
- Command not found
- Permission denied
- File not found
- Other system errors
- CTRL+C terminates the current command but not the shell
- The shell supports up to 100 history entries
- Pipes can be chained up to 10 times in a single command