Archive

Monthly Archives: January 2014

How would a better shell look like?

There are aspects of shells that are important but have a somehow exterior character, for instance good completion support, fancy prompts, or aliases. We dont consider those things here but aim to scetch the core syntax and features of a useful shell-and-script language that fits better to non-expert users than bash does.

A simple approach is to combine bash/sh features with a more benign language such as . Such a hypothetical language, “mesh”, has a tcl-like syntax but knows concept as sh-environments, anonymous and named pipes. Here are example mesh snippets:

 
ls A/ | grep _old 
procedure cleanUp { targetDir } {
	set now      [ clock seconds ]
	set maxAge   3600  
	set all     [ glob -nocomplain "targetDir/*" ]
	set trashed [ list ]
	set kept    [ list ]
	foreach {path access} [ stat -c "%n %X" $all ] { 	   	
		if { $now - $access  >  $maxAge } { 
			lappend trashed $path
		} else {
			lappend kept $path
		}
	}

	set trash    "$targetDir/old"
	mkdir $trash
	mv {*}$trashed $trash	

	return $kept
 }

Tcl is a proximate meshing-partner for bash because it also uses polish notation. However, tcl has its down-sides too. Arguments are passed by value, for object manipulation you therefore have to trick around by passing the variable name. Technically, there is only one (returnable) data type, strings, and you cannot distinguish between a word and a list containing a word, or between a list with even number of entries and a dict/mapping.

Still, the syntax of tcl solves the conflict between convenience of polish notation for one-liners versus the fit for structured scripts much better that bash does. Bash, on the other hand, better integrates into the system by direct access to executables and pipes/redirection.

An attractive though vague solution would be to combine bash/sh-feature and tcl-syntax in the way depicted above along with basics container types as used by lua and object piping as in PowerShell. The most difficult part probably is to make up syntax that supports structured types but is still as simple as the tcl-syntax is now.