简体   繁体   中英

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.

使用算术语句,在解析过程中需要较少的空格。

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

Rather than dealing with whitespace I would create a wrapper script:

#!/bin/bash
# /usr/local/sbin/foo-wrapper
/bath/to/foo
test $? -ne 6

pam config:

... pam_exec.so /usr/local/sbin/foo-wrapper

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM