Skip to content

arnodel/meshell

Repository files navigation

Meshell

How hard is it to write your own shell? I'm trying to find out!

Installing

Not sure you want to do that :) Anyway:

go install github.com/arnodel/meshell

Running

$ meshell gives you a repl

$ meshell script.sh runs a shell script. You can also do $ meshell <script.sh.

Features

  • cd builtin
  • exit builtin
  • shift builtin
  • simple commands (ls -a)
  • pipelines (ls | grep foo)
  • and, or lists (touch foo || echo ouch)
  • command lists (sleep 10; echo "Wake up!")
  • redirects to files (ls >my-files, echo onions >>shopping.txt, go build . 2> build_errors)
  • redirect stdin (cat <foo >bar)
  • redirect to fd (./myscript.sh 2>&1 >script_output.txt)
  • command groups ({echo "my files"; ls})
  • subshells ((a=12; echo $a))
  • env variable substitutions (echo $PATH)
  • tilde expansion (PATH=$PATH:~/bin) - hard to know what the rule is! (use $HOME for now)
  • simple parameter substitution (echo ${var})
  • general parameter expansion (echo ${PATH:stuff}) - that's a rabbit hole
  • command substitution (ls $(go env GOROOT))
  • shell variables (a=hello; echo "$a, $a!")
  • functions with return (function foo() {echo $2; return; echo $1}; foo hello there )
  • local variables
  • if then else if cond; then echo foo; elif cond2; then echo bar; else exit; fi
  • while loops while [ $# -gt 0 ]; do echo $1; shift; done
  • for loops
  • export (export a=10)
  • arguments (echo $1 ${2})
  • arg list (echo $@ ${@})
  • arg count (echo $# ${#})
  • status code (mycommand; echo $?)
  • PID (echo $$)
  • expressions [[ x = y ]]
  • arithmetic (( x = y+1 ))
  • comments echo no comment # Print "no comment"
  • add more to the list

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages