Skip to main content
  1. Projects/

Go Shell

··449 words·3 mins

Now that I am mostly done with my Final Year Project, I am looking at different projects to learn more about Golang. Go is an open source programming language supported by Google which has concurrency built into it. To run a concurrent program in Go, we just make use of the keyword go func() to run it in parallel.

Go also have channels to help with communications between channels using the chan keyword. This is a very powerful feature of Go which I will be using in this project.

A good way to learn a new programming language is to make a project using it. I have decided to make a shell in Go as it is a good way to learn the language and also to learn how to make concurrent programs.

What is a shell? #

A shell is a command line interface that allows us to interact with the operating system. It is a program that takes in commands and executes them. The most common shell is the bash shell which is the default shell for most Linux distributions.

In this project, we will be making a basic subset of the bash shell. We will be able to run commands like ls, cd, pwd, cat and exit. If there is additional time, we will add in some other commands for fun.

Goals of the project #

The goal of this project is to practice my go programming skills to prepare myself for my full time job, which may require me to use go. I will also be using this project to learn more about go and how to use it to make concurrent programs.

We will implement the following:

  1. A basic shell that can run commands.
  2. Piping between commands.
  3. Running multiple commands in 1 time.
  4. Some basic commands for a shell.

Project Structure #

The project will be split into 3 main parts:

  1. The shell itself
  2. The commands that the shell will run
  3. The tests for the shell

To view the full code, you can visit the Github Repository.

The Shell #

As the scope of the project is small, the shall will just do the following:

  1. The shell will take in a command from the user.
  2. The shell will parse the command and split it into the command and the arguments.
  3. The shell will then check if the command is a built-in command.
  4. If it is a built-in command, the shell will run the command.
  5. If it is not a built-in command, the shell will check if the command is a valid executable.
  6. If it is a valid executable, the shell will run the command.
  7. If it is not a valid command, the shell will print an error message.