Any shell command can be executed, using
Executes shell-command as a shell command.
The expansion of
syscmdis void, not the output from shell-command! Output or error messages from shell-command are not read by
m4. See Esyscmd, if you need to process the command output.
Prior to executing the command,
m4flushes its buffers. The default standard input, output and error of shell-command are the same as those of
By default, the shell-command will be used as the argument to the -c option of the /bin/sh shell (or the version of sh specified by ‘command -p getconf PATH’, if your system supports that). If you prefer a different shell, the configure script can be given the option --with-syscmd-shell=location to set the location of an alternative shell at GNU
m4installation; the alternative shell must still support -c.
syscmdis recognized only with parameters.
define(`foo', `FOO') ⇒ syscmd(`echo foo') ⇒foo ⇒
Note how the expansion of
syscmd keeps the trailing newline of
the command, as well as using the newline that appeared after the macro.
The following is an example of shell-command using the same
standard input as
$ echo "m4wrap(\`syscmd(\`cat')')" | m4 ⇒
m4 to read all of its input before executing the wrapped
text, then hand a valid (albeit emptied) pipe as standard input for the
cat subcommand. Therefore, you should be careful when using
standard input (either by specifying no files, or by passing ‘-’ as
a file name on the command line, see Invoking m4), and also invoking subcommands via
that consume data from standard input. When standard input is a
seekable file, the subprocess will pick up with the next character not
yet processed by
m4; when it is a pipe or other non-seekable
file, there is no guarantee how much data will already be buffered by
m4 and thus unavailable to the child.