HsShellScript is a library which makes it easy to do typical shell scripting tasks in Haskell.
Command Line Arguments Parser
HsShellScript has facilities for managing command line arguments,
which are easier to use than the GHC library GetOpt. Command line
arguments are specified as lists of properties. HsShellScript builds
on top of GHC’s GetOpt, but hides it completely. Command line
arguments handling has been added because GetOpt seemed too
cumbersome.
Easy Interface to External Programs
Calling programs and recognizing errors (via exitcode or exception)
is made more easy. There are front end functions for common
programs, such as /bin/mv
or /bin/chmod
.
Analyzing Paths
Dealing with paths is not as trivial as it sounds. Take, for example
../foo.bar//./../baz/
(and split off the extension of the
file name…). HsShellScript solves this thoroughly and provides
functions for such tasks as splitting a path in directory and file
name parts, splitting a path into path components, or syntactically
normalising paths.
Redirecting Input and Output
HsShellScript defines operators like ->-
and ->>-
which work like redirection operators in shells.
Building Pipes
Reading the output of an external program, or piping the output of
one program into the input of another, is almost as easy as in
shells. HsShellScript provides corresponding operators.
Error Handling
Error handling is one thing which is done more thoroughly in
HsShellScript than in shells. Failed programs won’t be silently
ignored. Exceptions are used for error handling. Non zero
exit codes get thrown in the form of expressive RunError
exceptions.
Quoting of Strings and Building Commands for Shells
Taking care of shell metacharacters usually isn’t done right. HsShellScript provides functions for doing it
safely.
Non-broken, Secure Functions for Creating Temporary Files and Directories
The standard C library has mkstemp
, mktemp
, tempnam
, tmpfile
and tmpnam
, which are all broken,
non-portable or unsuitable in some way.
HsShellScript is quite old, already - some 20 years old. During the last years, changes have mostly been bug fixes and quality improvements, as well as portings to new GHC versions (necessary because of incompatible changes). So it is pretty stable and well-tested.
HsShellScript is mature and documented. Most parts have been tested in use by me since 2004.
I’ve ported HsShellScript to base >= 4.17.0.0 && < 5 (GHC 9.4.4 and up). That’s the recommended version (as of 2024-04-02). From what I’ve learnt, I set the bounds of the version of the base package to “>= 4.17.0.0 && < 5”.
HsShellScript is distributed via the Cabal system and its package server Hackage. This means that you don’t install it. You just use it and Cabal will do the rest.
You can still download it from Gitlab, if you like.
The sources of the old versions, from before I switched to Gitlab (up to 3.5.0), are here.
The API documentation is linked on the project’s Hackage page, under “Modules”.
There used to be sort of a usage manual, but that's outdated and pointless now. The API documentation is elaborate and also includes some examples.
The email addresses are obfuscated a litte in order to repulse spammers. Insert an @-sign and dots in the email addresses as needed.
This is free software, released under the GNU Lesser General Public License (LGPL), version 2.1, or any later version.
This page was last changed on 2024-04-03.