Advanced Programming course assignment 1
MyShell is a shell program developed as part of our Advanced Programming course assignment. The program is designed to interpret and execute user commands in a simulated shell environment. It includes features commonly found in Unix-like shells,such as command execution, redirection, pipelining, handling variables, and control flow.
- GCC compiler
- A Unix-like environment
To compile the shell program, use the following command in your terminal:
make
To start the shell, run:
./myshell
The shell supports a variety of commands and features as described below:
-
Command Execution
- Execute commands with arguments.
hello: ls -l
-
Background Execution
- Execute commands in the background using
&
.
hello: ls -l &
- Execute commands in the background using
-
Redirection
- Redirect output to a file using
>
.
hello: ls -l > file
- Append output to a file using
>>
.
hello: ls -l >> mylog
- Redirect standard error using
2>
.
hello: ls -l nofile 2> mylog
- Redirect output to a file using
-
Pipelines
- Use pipes to direct the output of one command as the input to another.
hello: cat myfile | grep "search_term"
-
Variable Handling
- Set and use variables.
hello: $person = David hello: echo $person
-
Read Command
- Prompt for input and store in a variable.
hello: read name hello: echo $name
-
Command History
- Navigate through recent commands using the up and down arrow keys.
-
Control Flow
- Implement if-else conditions.
if date | grep Fri then echo "Shabat Shalom" else echo "Hard way to go" fi
-
Change Prompt
- Change the command prompt display.
hello: prompt = myprompt
-
Change Directory
- Change the current working directory.
hello: cd mydir
-
Repeat Last Command
- Repeat the last executed command using
!!
.
hello: !!
- Repeat the last executed command using
-
Exit
- Exit the shell using
quit
.
hello: quit
- Exit the shell using
-
Interrupt Handling
- Handle Ctrl-C interrupts gracefully, printing a message rather than terminating.