This is a simple shell program implemented in C. The program reads user input, tokenizes the command, and uses fork()
and execvp()
system calls to execute the command. The current time is displayed before each command prompt.
- Displays the current time before each command prompt.
- Supports basic shell commands like
ls
,pwd
, etc. - Exits when the user types
exit
. - Handles child process creation and execution using
fork()
andexecvp()
. - Error handling for unknown commands and unsuccessful child process creation.
Ensure that GCC (GNU Compiler Collection) is installed on your system.
Ubuntu or Debian-based systems:
sudo apt update
sudo apt install gcc
Fedora, RHEL, or CentOS:
sudo dnf install gcc
Arch Linux:
sudo pacman -S gcc
To verify the installation:
gcc --version
To install GCC on Windows, you can use MinGW (Minimalist GNU for Windows) or Cygwin.
MinGW Installation Steps:
- Download the MinGW installer from the MinGW website.
- Run the installer and select the
gcc
package. - Follow the prompts to complete the installation.
- Add the path to MinGW (
C:\MinGW\bin
) to your system’s PATH environment variable:- Right-click on
This PC
orComputer
>Properties
>Advanced system settings
>Environment Variables
. - Find the
Path
variable inSystem variables
, clickEdit
, and addC:\MinGW\bin
.
- Right-click on
To verify the installation:
gcc --version
Cygwin Installation:
- Download and run the Cygwin installer from Cygwin’s official site.
- During installation, select the
gcc-core
package. - Follow the steps to complete the installation.
- Add the Cygwin
bin
directory (e.g.,C:\cygwin64\bin
) to your PATH environment variable.
Clone the repository and navigate to the directory containing the source file. Use GCC to compile the program:
gcc -o simple_shell simple_shell.c
This will create an executable file named simple_shell
.
Run the compiled program using:
./simple_shell
Run the compiled program using:
simple_shell.exe
If you encounter issues with fork()
or execvp()
on Windows, consider running the program in a Linux environment using Windows Subsystem for Linux (WSL) or using a virtual machine with Linux installed.
- The program displays the current time before each command prompt.
- Type any valid shell command and press Enter to execute it.
- To exit the shell, type
exit
and press Enter.
- GeeksforGeeks - Array of Strings in C
- Stack Overflow - Split String into Tokens
- Tutorials Point - Local Time Function
- Execvp Documentation
For more details, check out the comments and links within the code.
This project is licensed under the MIT License.