Skip to content

trenthuber/thus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thus

thus is a custom Unix shell for POSIX platforms.

Features

  • Job control (fg, bg, &, ^Z)
  • Pipelines
  • Conditional execution (&&, ||)
  • File redirection (<file, 2>&1, etc.)
  • Globbing (*, ?, [...])
  • Quoting ('...', "...")
  • Variables (set, unset, $VAR$, etc.)
  • Aliasing (alias, unalias)
  • Configuration files (~.thuslogin, ~.thusrc)
  • Cached history (~.thushistory)
  • Automated integration of built-in commands

Building

thus uses cbs as its build system.

> git clone --recursive https://trenthuber.com/git/thus.git
> cd thus/
> cc -o build build.c
> build

After building, you can use install to add the shell to your path. The default installation prefix is /usr/local/, but a custom one can be passed as an argument to the utility.

> sudo ./install

After installing, you can use uninstall to remove the shell from the install location.

> sudo ./uninstall

Quirks

While thus operates for the most part like Bourne shell, there are a few places where it takes a subtly different approach.

Quotes

Like most other shells, variables, tildes, and escape sequences will be expanded inside of double quotes, but not single quotes. Unlike other shells however, quotes do not concatenate with other arguments that are not separated from the quote by whitespace. For example, the command echo "foo"bar would print foo bar whereas other shells would combine them into a single argument and print foobar.

Variables and aliases

Variables are referred to by strings of characters that begin and end with a $. For example, evaluating the path variable would look like $PATH$. Setting variables is done with the set built-in command, not with the name=value syntax. This syntax is similarly avoided when declaring aliases with the alias built-in command.

Additionally, all shell variables are automatically made to be environment variables, so there's no need to export variables.

Leading and trailing slashes

Prepending ./ to executables located in the current directory is not mandatory unless there already exists an executable in $PATH$ with the same name that you would like to override.

The $HOME$, $PWD$, and $PATH$ variables are always initialized with trailing slashes. Therefore, whenever one of these variables or ~ is substituted in the shell, it will retain the trailing slash.

File redirection

If there is whitespace between a file redirection operator and a filename following it, then it is not parsed as a file redirection, but instead as two separate arguments. Something like ls >file would redirect the output of the ls command to file, whereas ls > file would list any files named > and file.

Resources

Contributors

Languages