Updated Mar 21, 2016

Be Brash!

These pages describe how to use brash -- which is a true Windows "clone" of the bourne shell with a few features from GNU bash thrown in. It also integrates the key features of several unix command line tools into itself to eliminate the need to download a whole planet's worth of s/w just to get normal command line functionality working.

By saying "a true Windows clone", it is meant that the program is written as a normal windows multi-threading executable without the need for GNU the simulation of the unix fork/exec behavior. It also means that windows file names are expected, not a simulation of the unix directory structure. Note that brash is a recoding of the bourne shell from scratch -- it is not a modification of the original bourne or brash shell code. As such there are some differences which are discussed below.

These pages do not include a complete programming guide to the bourne shell -- there are plenty of pages on the internet that do that. GNU Bash web pages will likely describe how to solve most programming problems in a manner that is consistent with how brash does it as well.

There are of course differences between the built-in commands in "brash", "bash" and the "bourne" shell. Click Here for details.

What's it for?

Brash exists to serve both as a convenient way to execute commands in a Windows console window and to provide "bourne" style script language execution -- including the definition of script language functions at the console and executing them.

It is distributed in source code form so that it can also serve as platform for creating "application specific" command libraries that operate at c++ program speeds rather invoking separate executables that invoke one another. Basically, you can string commands together using the built-in piping feature of the language and these commands can be written in C++.

Like cmd.exe, brash has the ability to page backwards through commands that you have previously executed using the up and down arrow keys -- so that you can easily re-execute any one of them. But, like the bourne shell and GNU bash, it has the ability to convert this command history into a file and let you edit your history for seamless re-execution as if the modified lines were stored in a script file. See the "fc" command.

Unlike the windows command program, cmd.exe, you will not see any irregularities and special cases in the meaning of statement syntax. You also get a lot more string manipulation functionality and regular expression functionality built into the interpreter. See the section on scripting, below, for more details.

One annoyance with brash, as with the bourne shell when run on Windows, is that the backslash character, (\), is an escape character. This means that when specifying file names, you must use double-backslashes instead of single-backslashes most of the time. Luckily, the brash console input mechanism has a way of automatically converting forward slashes (/) into double-backslashes -- you type in the name of a file and then you press the tab key. The tab key is also used for file name completion -- so, in brash, it also converts the forward slash into double backslashes. Unless the cursor is inside an apostrophe quoted string -- see the section on the console for more details.

Brash integrates the key features of a variety of unix-like tools built into a single executable:

ls diff grep sed set
env basename dirname wc
cut cat head stat
Since these commands are "built-in", they have no program launch time. Scripts written using brash's builtin versions of these commands can be dramatically faster than having to launch separate programs to do these things.

It should be noted that the builtin versions are only "like" the corresponding unix commands. They typically only implement the most commonly used feature of those normaly external commands.

To reduce confusion, the versions of the above commands which are built into brash may have different names -- or a leading dot (.) at the beginning of the name. This lets you mix and mingle real GNU executables with the builtin versions when you find that you need more functionality than brash provides. This lets you go to source-forge and pull down the WIN32 versions of grep, sed, or whatever, and use it seamlessly with the brash builtins.

As an example, the grep functionality is approximated by the command ".regex -fl -m pattern files ...". Use its -h option for more details. Some of the sed functionality is also implemented in the .regex command.

The above subset of unix command line tools were chosen for inclusion in the baseline code base because these tools are strongly correlated with writing scripts.

There are lots of other commands which are builtin to brash. Use the command, builtins, to get a list. Use the -h option to the commands for more details.

Running Brash

To run brash in a realistic way, you must have a working .brashrc file. This configures default environment variables, aliases, and shell functions. An example of of a startup file is provided along-side the brash.exe program.

The installation process only has 3 steps:

  1. download brash.exe into somewhere into your PATH
  2. download brashrc to the directory %USERPROFILE% and rename it to .brashrc
  3. configure any new scripts or environment variable settings you want to make
After this is done, use
brash -h
to get a list of command line options.

Once brash is up and running, use

builtins
to get a list of built-in commands.

For scripting examples, any web search for the bourne shell way of doing things should apply to brash. (With a small number of exceptions listed elsewhere in this website.)

Brash Console Interaction

Click Here

Brash Script Language

Click Here

Extending Brash

The source for brash is publicly available and it is fairly simple to add your own built-in commands by following source code examples -- such as for the code for the builtin commands like: Of course, you must write thread safe code in doing so.

Look in cxx/brash/brashBuiltins.cxx for the classes

These functions are mostly simple I/O and math operations but they do show how to read and write files and produce error message, etc.

To create a new command:

  1. Create a new class named something like: BrashBuiltinXYZExecutor

    Add it to brashBuiltins.cxx

    Also add the name of the command to the table at the bottom of the file
  2. Execute the build.bat script and test.