Skip to content

Repository files navigation

BESH

Bemly's Shell — a Unix shell written in Rust with libc.

Inspired by lsh.

Features

  • Interactive REPL with colored prompt
  • Command pipelines (cmd1 | cmd2 | cmd3)
  • I/O redirection (>, >>, <, 2>)
  • Background jobs (cmd &, jobs)
  • Tab completion (commands + file paths)
  • Arrow key history navigation
  • Line editing (Ctrl+A/E/K/U)
  • Environment variable management
  • Script execution (.besh files)
  • Signal handling (Ctrl+C, Ctrl+Z)
  • Job control

Build

git clone https://github.com/Bemly/Besh.git
cd Besh
cargo build --release

The binary is at target/release/besh.

Optionally install to ~/.cargo/bin:

cargo install --path .

Usage

Interactive Mode

./target/release/besh
user@hostname ~> ls -la
user@hostname ~> echo hello world
user@hostname ~> exit

Single Command

./target/release/besh echo"hello world"
./target/release/besh ls -la /tmp

Script Execution

cat > test.besh << 'EOF'#!/usr/bin/env beshecho "Running script"export VAR=valueecho $VARls -la | head -3EOF
./target/release/besh test.besh

Built-in Commands

CommandDescription
cd [path]Change directory (supports ~)
pwdPrint working directory
echo [args...]Print to stdout
export VAR=valSet environment variable
unset VARUnset variable
envPrint all environment variables
setPrint all shell variables
history [n]Show last n commands
jobsList background jobs
exit / quit / qExit shell

Pipes & Redirection

# Pipe
cat file.txt | grep "pattern"| wc -l
# Output redirect
ls -la > listing.txt
# Appendecho"line">> file.txt
# Input redirect
sort < unsorted.txt
# Stderr redirect
ls /notfound 2> errors.txt

Background Jobs

sleep 60 &jobs

Tab Completion

  • Press Tab to complete commands and file paths
  • First word: completes built-in commands and executables from $PATH
  • Other words: completes file/directory paths
  • Multiple matches are displayed, common prefix is auto-completed

Line Editing

KeyAction
/ Move cursor
/ Navigate history
TabComplete
Ctrl+AMove to start
Ctrl+EMove to end
Ctrl+KDelete to end of line
Ctrl+UDelete to start of line
Ctrl+CCancel input
Ctrl+DEOF / exit

Environment Variables

export PATH=/usr/local/bin:$PATHexport EDITOR=vim
echo$HOMEecho$USER

Disable Colors

NO_COLOR=1 ./target/release/besh

CLI Options

besh Enter interactive shell
besh <command [args]> Execute a single command
besh <script.besh> Execute a script file
besh -h, --help Show help
besh -v, --version Show version

Project Structure

src/
├── main.rs Entry point
├── shell.rs REPL loop and command execution
├── parser.rs Command line parsing (pipes, redirects, variables)
├── process.rs Fork/exec/wait via libc
├── terminal.rs Raw mode, line editing, tab completion, colors
├── builtin.rs Built-in command implementations
├── environment.rs Variable management and prompt formatting
├── history.rs Command history with file persistence
├── job_control.rs Background/foreground job management
├── signal.rs SIGINT, SIGTSTP, SIGCHLD handlers
├── error.rs Error types
├── common_shell.rs Legacy stdlib-based shell (fallback)
└── better_truth_tty.rs Placeholder for future libc shell

API documentation is generated in docs/ via cargo doc.

Dependencies

  • libc — POSIX system calls
  • dirs — Home directory detection

License

See LICENSE.

About

Bemly_ Shell is a simple shell, written in Rust.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages