Interacting with the System
m4 is a Turing-complete programming language, but many tasks are better left to specialized power tools. m4 designers allow you to utilize the services the host operating system provides.
The syscmd(cmd) macro executes the specified cmd—a program or a script with or without command-line options. The command may include pipes, I/O redirection, and even background execution. Anything permissible on the shell command line is permissible as an argument to syscmd. The macro displays the output of the cmd on the screen but doesn’t feed it into the m4 pipeline. For example, the following macro expands to an empty string and displays the number of files in the current working directory:
| | syscmd(ls | wc -l) |
| | dnl Output: ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access