简体   繁体   English

不用空格重写Shell脚本

[英]Rewrite shell script without whitespace

Is it possible to write a shell script like that without using spaces, tabs or newlines: 是否可以在不使用空格,制表符或换行符的情况下编写像这样的shell脚本:

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

The script runs another program and fails iff its return code is 6. 该脚本运行另一个程序,并且失败,如果其返回码为6。

Background 背景

I use this together within pam_exec.so and another program that controls access to a system. 我在pam_exec.so和另一个控制对系统访问的程序中一起使用。 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). 它与安全性无关,如果其他脚本(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. 我目前使用包装器脚本,但是再次需要部署该脚本,并且我需要确保该脚本的部署与pam配置一致。 I would prefer a self-contained portable solution within the pam configuration. 我希望在pam配置中使用独立的便携式解决方案。

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 不幸的是1) pam_exec.so不在乎它调用的程序的返回代码,2)pam.d配置解析器不在乎引号,它只是将参数用" \\n\\t" pam_exec.so ,所以我不能采用

... 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配置:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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