M4sh, pronounced “mash”, is aiming at producing portable Bourne shell scripts. This name was coined by Lars J. Aas, who notes that, according to the Webster's Revised Unabridged Dictionary (1913):
Mash \Mash\, n. [Akin to G. meisch, maisch, meische, maische, mash, wash, and prob. to AS. miscian to mix. See “Mix”.]
- A mass of mixed ingredients reduced to a soft pulpy state by beating or pressure...
- A mixture of meal or bran and water fed to animals.
- A mess; trouble. [Obs.] –Beau. & Fl.
For the time being, it is not mature enough to be widely used.
M4sh provides portable alternatives for some common shell constructs that unfortunately are not portable in practice.
Run shell code test1. If test1 exits with a zero status then run shell code run-if-true1, else examine further tests. If no test exits with a zero status, run shell code run-if-false, with simplifications if either run-if-true1 or run-if-false1 is empty. For example,AS_IF([test "$foo" = yes], [HANDLE_FOO([yes])], [test "$foo" != no], [HANDLE_FOO([maybe])], [echo foo not specified])
ensures any required macros of
HANDLE_FOOare expanded before the first test.
Make the directory file-name, including intervening directories as necessary. This is equivalent to ‘mkdir -p file-name’, except that it is portable to older versions of mkdir that lack support for the -p option. Also,
AS_MKDIR_Psucceeds if file-name is a symbolic link to an existing directory, even though Posix is unclear whether ‘mkdir -p’ should succeed in that case. If creation of file-name fails, exit the script.
Also see the
AC_PROG_MKDIR_Pmacro (see Particular Programs).
Initialize the shell suitably for
configurescripts. This has the effect of
AS_BOURNE_COMPATIBLE, and sets some other environment variables for predictable results from configuration tests. For example, it sets LC_ALL to change to the default C locale. See Special Shell Variables.
# This outputs "#define HAVE_CHAR_P 1". type="char *" echo "#define AS_TR_CPP([HAVE_$type]) 1"
# This outputs "Have it!". header="sys/some file.h" AS_TR_SH([HAVE_$header])=yes if test "$HAVE_sys_some_file_h" = yes; then echo "Have it!"; fi