sor*_*rin 5 bash shell shebang
是否知道大多数shebang实现都支持单个参数,所以如果你有类似的东西
#!/usr/bin/env some-tool-accepting-yaml param1 param2
... (yaml body)
Run Code Online (Sandbox Code Playgroud)
它现在将按预期工作,因为它将使用"param1 param2"参数调用该工具,而不是将其拆分为两个参数.
似乎一种解决方法是使用类似的东西:
#!/bin/sh
arbitrary_long_name==0 "exec" "/usr/bin/gawk" "--re-interval" "-f" "$0" "$@"
Run Code Online (Sandbox Code Playgroud)
现在这种方法会使基于YAML的脚本由于第二行而无效,因此唯一可接受的解决方法是也是注释,也以"#"开头.
有没有办法绕过这个问题呢?
不使用多语言脚本的通用解决方案
#!/bin/bash
# first argument to be split
if [[ $- != *f* ]]; then reset=1; fi
set -f
arg=( $1 )
shift
if [[ $reset = 1 ]]; then set +f; fi
# other arguments
arg+=("$@")
# launch command
exec "${arg[@]}"
Run Code Online (Sandbox Code Playgroud)
#!/path/to/launcher.sh interpreter opts
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
330 次 |
| 最近记录: |