为像expect这样的程序指定通用解释器?

mun*_*ish 5 executable shell-script interpreter

我正在编写可在多个操作系统上使用的期望脚本,但问题是

我不能使用#!/usr/bin/expectevreywhere 所以我试着做

 #!`which expect`
Run Code Online (Sandbox Code Playgroud)

在顶部,但失败了

[sesiv@itseelm-lx4151 ~]$ ./sendcommand
-bash: ./sendcommand: `which: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)

对此的任何解决方案。

Bru*_*ger 7

一种最有效的技巧(对于 perl、python、php 解释器,可能还有其他):

#!/usr/bin/env expect
Run Code Online (Sandbox Code Playgroud)

我认为env总是在/usr/bin/. 现在很多解释器都可以这样运行。其他黑客曾经存在,但无法理解,或者不是那么便携。