Skip to content

trenthuber/thus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thus

thus is a custom Unix shell for POSIX platforms.

Features

  • Job control (fg, bg, &, ^Z)
  • Pipelines
  • File redirection (<file, 2>&1, etc.)
  • Globbing (*, ?, [...])
  • Quotes ('...', "...")
  • 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.

Sequential command execution

Most other shells by default will execute all the commands in a line regardless of the previous one's exit status. Typically, in order to control whether a command runs based on the exit status of the last, these shells provide list operators like && and ||. Neither of the these operators are included in this shell. Instead, the && operator is the default behavior between commands, while the || operator is forgone entirely. If any command fails, the whole string of commands fail whether from a script or from an interactive session.

Quotes

Like 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 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 a 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 that might be named > or file.

Resources

References

About

A Unix shell

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages