This is a simple custom shell implemented in C++ that supports basic Unix commands, input/output redirection, piping, and command history.
- 📂 Execute common Unix commands like
ls,pwd,mkdir, etc. - 🔄 Input and output redirection using
<,>, and2>. - 🚰 Piping between commands using
|. - ⏳ Background command execution using
&. - 📜 Command history and recall using
!!and!n. - 🚪 Creation and usage of named pipes (FIFOs) using
mkfifo.
- 🛠️ A C++ compiler (g++ recommended)
- 🐧🍏 Unix-like operating system (Linux, macOS)
To compile the shell, use the following command:
g++ -o custom_shell custom_shell.cppAfter compiling, you can run the shell with:
./custom_shellYou can run basic Unix commands like pwd, ls, mkdir, etc. Example:
( Enter Command ) : pwdRedirect input from a file using <, and output to a file using >. Example:
( Enter Command ) : sort < input.txt > output.txtRedirect standard error using 2>. Example:
( Enter Command ) : ls non_existent_file 2> error.txtUse | to pipe the output of one command to another. Example:
( Enter Command ) : sort testing.txt | grep anyword | cat > a.txtRun a command in the background using &. Example:
( Enter Command ) : sort testing.txt > sorted.txt &- View command history with
history. - Recall the most recent command with
!!. - Recall a specific command with
!n(wherenis the command number).
Create a named pipe using mkfifo. Example:
( Enter Command ) : mkfifo fifo1Write to and read from a named pipe:
( Enter Command ) : cat fifo1&
( Enter Command ) : echo "hello" > fifo1pwdlsls -lmkdir folderNameexit&command(e.g.,&pwd)sort < input.txt > output.txtcd directoryPathls non_existent_file 2> error.txtman ls > ls.datcat input.txtcat input.txt output.txt > combined.txttr -s '[:space:]' '\n' < sortingFile.txtsort testing.txt | grep anyword | cat > a.txtsort testing.txt | grep anyword > a.txt | wc -lsort ls.dat | tee a.txttouch newFile.txtnano newFile.txtecho "coding is fun" > fifo1rm fifo1echo "code"sort testing.txt | tee a.txtsort testing.txt | tee a.txt | wc -lsort a.txt > fifo1ls | tee listing.txt | grep .cpp
When writing data to a FIFO, the write will block until another process reads from it. Ensure that there is a process reading from the FIFO to avoid indefinite blocking.
Contributions are welcome! Feel free to open issues or submit pull requests. 🤝
This project is licensed under the MIT License. See the LICENSE file for details.
git clone https://github.com/maazkhandev75/CustomLinuxShell.git


