User Tools

Hacking Cafe

Hacking Cafe is a Unix/Linux and Bash simulator in the browser. This project is a continuation of Fake Linux Terminal. The source code is released under the GNU AGPL license and can be found on GitHub.

Bash syntax

Implemented bash syntax:

  • variables
  • : and . shortcuts (for true and source commands)
  • subshells $(...), (...), and `...`
  • double-quote expressions
  • variable assignments
  • arrays
  • pipes
  • redirects (>, >>, and <)
  • JavaScript programs using web workers
  • Bash scripts
  • custom interpreters with shebang
  • glob patterns
  • for
  • if
  • &&/||
  • while, until
  • while read line
  • case/esac
  • read -p "continue? (y/n) "

Functions

  • name() { ...; } and function name { ...; }
  • positional parameters $1, $#, $*, $@ scoped to the call
  • visible in subshells, pipelines and command substitution
  • redirects on the call, f > file
  • return
  • shift

Default variables

  • $PS1 - controlling the prompt
  • $PATH - list of paths separated by : where executables are searched
  • $IFS - controlling splitting text into fields
  • $? - exit code from last command
  • $PWD - current working directory
  • $0-$9 - arguments to bash scripts
  • $@ / $* / $# - all args and length of args

Variable expansions

  • ${DATABASE_URL:="localhost"}
  • USER_ID=${1:?"Error, arg missing!"}
  • ${VAR:-default}
  • ${VAR-default}
  • ${var+alternative}
  • ${var:+alternative}
  • ${VAR/x/y} - replace
  • ${VAR//x/y} - replace all
  • ${TEXT:4} ${TEXT:0:4} - slice
  • ${FILE%.*} - remove trailing non-greedy
  • ${PATH%%:*} remove trailing greedy
  • ${PATH##*/} - remove greedy before
  • EXTENSION=${FILE#*.} - remove before
  • ${NAME^} - camel case
  • ${NAME^^} - upper case
  • LEN=${#NAME} - string length
  • ${!POINTER} - indirect variable

Build commands

Some of them should be in the /bin directory.

  • cat - concatenates the files or reads from stdin
  • grep - global regex print
  • echo - prints to the stdout
  • printf - similar to echo
  • kill - kill the process
  • exit - exit the bash script
  • ps - list processes (bash is always 0)
  • rm - remove file
  • cd - change directory
  • mkdir - make directory
  • pwd - print working directory
  • ls - list directory
  • adduser (create home directory, but there is no login yet)
  • source - includes the bash script in the current shell
  • chmod - change permissions
  • ln - create symlinks (hard links not supported)
  • read - reads a line from stdin and splits it using $IFS.
  • test - various checks on files and compares values
  • pushd/popd - stack-based navigation
  • dirs - print current stack
  • export - export variable (so it can be accessed in a subprocess)
  • unset - remove variable

Default file system

|-- bin
|   |-- cowsay
|   |-- false
|   |-- figlet
|   |-- highlight
|   |-- js
|   |-- python
|   |-- sleep
|   |-- true
|   `-- vi
|-- etc
|   |-- bashrc
|   `-- passwd
`-- root

Custom Commands

  • fetch (neofetch)
  • rfc (RFC viewer using less)
  • less
  • record - save commands in URL hash
  • credits
  • help

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information