In groff, is there a way to ".so" a file if but only if the file exists? I either want to do ".so file" and have it proceed without error message if the file doesn't exist, or have something I can put in a .if to check first. (If there's a command-line option to suppress ALL error messages, that's no good, that's going to prevent me from fixing actual errors.)

If there's no way to do this directly in groff, I'll make an enclosing shell script which checks whether the file exists and either emit the .so command or not as applicable, but if there's a within-groff method that would be simpler.

2 Answers 2


There is an unsafe way to solve this, which includes the roff request .pso to execute a shell command:

.pso if [ -f file ]; then cat file; fi

You would have to run groff with -U for this to work, or you will get a diagnostic message saying

.pso request not allowed in safer mode

As far as I know, there is no built-in test that can be used to detect the existence of a file.


groff 1.23.0 has a new feature to cover your use case, I believe--the soquiet request. It doesn't expose tests of file system objects, but it does permit you to attempt to source a file without making noise if the file isn't found. You can then test for successful sourcing by checking to see if some register, macro, or string defined by the file has a definition.

Here's the announcement for the most recent groff 1.23.0 release candidate.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .