A lightweight command-line shell implementation written in Go. Part of the Codecrafters Build your own Shell challenge, the main initial stage. After this you have a bare basic shell you can run. For example git push or clone are now part of your shell. Or run external commands including your own custom scripts. Pretty cool to see that happening. 😎
- REPL Loop: Interactive prompt (
$) with standard input parsing and line trimming. - Builtin Commands:
exit: Gracefully exits the shell.echo: Prints arguments back to standard output.type: Checks whether a given command is a shell builtin or resolves its full binary path using$PATH.pwd: Prints the current working directory.cd: Changes the current working directory.
- External Command Execution: Locates and executes external binaries found in
$PATHusingos/exec, streamingstdoutandstderrback to the terminal. - PATH Resolution: Manual PATH inspection to inspect executable permissions (
0111) across directory splits.
- Go 1.20 or later installed on your system.
- Clone the repository:
git clone https://github.com/jim3/go-posix-shell.git
cd go-posix-shell- Run the shell directly:
go run main.go- Or compile and execute the binary:
go build -o go-posix-shell main.go
./go-posix-shell$ ./go-posix-shell
$ echo Hello, World!
Hello, World!
$ type echo
echo is a shell builtin
$ type ls
ls is /usr/bin/ls
$ type nonexistent
nonexistent: not found
$ exit