This is a custom shell program written in C that supports various features such as command execution, redirection, background execution, built-in commands, variable handling, and more. The shell provides an interactive environment for running commands similar to standard Unix shells.
- Basic Command Execution: Execute standard Unix commands with arguments.
- Redirection:
- Output redirection (
>
) - Append redirection (
>>
) - Error redirection (
2>
)
- Output redirection (
- Background Execution: Run commands in the background using
&
. - Built-in Commands:
- Change prompt (
prompt =
) - Print arguments (
echo
) - Change directory (
cd
) - Print the last command status (
echo $?
) - Exit the shell (
quit
) - Repeat the last command (
!!
)
- Change prompt (
- Signal Handling: Custom message on
Control-C
. - Pipes: Chain multiple commands with
|
. - Variable Handling: Set and use custom variables.
- Flow Control: Support for
if/else
statements. - User Input: Read user input and use it in commands.
- Command History: Navigate through command history using arrow keys.
To compile the shell program, use the following command:
make
To run the shell, execute:
./myshell
hello: ls -l
hello: ls -l > file
hello: ls -l >> file
hello: ls no_such_file 2> error.log
hello: prompt = myprompt
myprompt: echo abc xyz
myprompt: echo $?
myprompt: cd mydir
myprompt: pwd
myprompt: !!
myprompt: quit
hello: sleep 5 &
hello: $filename = "testfile.txt"
hello: echo "This is a test" > $filename
hello: cat $filename
hello: echo Enter your name:
hello: read username
hello: echo "Hello, $username!"
hello: if grep -q "pattern" file.txt
hello: then
hello: echo "Pattern found"
hello: else
hello: echo "Pattern not found"
hello: fi
hello: cat file.txt | grep "search" | sort | uniq
Notes:
- Use
Ctrl + C
to test the custom signal handling(eliminate child processes but not the parent). - Navigate through command history using the up and down arrow keys.
- The
if
command is actuallize in one row(as in the examples above).