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 (fortrueandsourcecommands)- subshells
$(...),(...), and`...` - double-quote expressions
- variable assignments
- arrays
- pipes
- redirects (
>,>>, and<) - JavaScript programs using web workers
- Bash scripts
- custom interpreters with shebang
- glob patterns
forif&&/||while,untilwhile read linecase/esacread -p "continue? (y/n) "
Functions
name() { ...; }andfunction name { ...; }- positional parameters
$1,$#,$*,$@scoped to the call - visible in subshells, pipelines and command substitution
- redirects on the call,
f > file returnshift
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 beforeEXTENSION=${FILE#*.}- remove before${NAME^}- camel case${NAME^^}- upper caseLEN=${#NAME}- string length${!POINTER}- indirect variable
Build commands
Some of them should be in the /bin directory.
cat- concatenates the files or reads from stdingrep- global regex printecho- prints to the stdoutprintf- similar to echokill- kill the processexit- exit the bash scriptps- list processes (bash is always 0)rm- remove filecd- change directorymkdir- make directorypwd- print working directoryls- list directoryadduser(create home directory, but there is no login yet)source- includes the bash script in the current shellchmod- change permissionsln- create symlinks (hard links not supported)read- reads a line from stdin and splits it using$IFS.test- various checks on files and compares valuespushd/popd- stack-based navigationdirs- print current stackexport- 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 usingless)lessrecord- save commands in URL hashcreditshelp