Search code examples
bashshellpam

Rewrite shell script without whitespace


Is it possible to write a shell script like that without using spaces, tabs or newlines:

/path/to/foo; test $? -ne 6

The script runs another program and fails iff its return code is 6.

Background

I use this together within pam_exec.so and another program that controls access to a system. It does not relate to security, and I want to ensure access to the system if something about that other script fails (other than rc 6). The other program is a bit brittle, may break for various reasons, or simply be unavailable due to a messed up installation. I currently use a wrapper script, but that again needs to be deployed and i need to ensure that deployment of that script is consistent with the pam configuration. I would prefer a self-contained portable solution within the pam configuration.

Unfortunately 1) pam_exec.so doesn't care for the return code of the program it calls, and 2) the pam.d config parser does not care for quotes, it just splits arguments by " \n\t", so I cannot use

... pam_exec.so /bin/bash -c "/bath/to/foo; test$? -ne 6"

I am curious if there is a way to reformulate that such that it does not need spaces and can be used here.


Solution

  • Use an arithmetic statement, which requires less whitespace during parsing.

    bash -c '/path/to/foo;(($?!=6))'