exec ${PERL-perl} -Sx $0 ${1+"$@"} 在 Shell 脚本中是什么意思? [英] What does exec ${PERL-perl} -Sx $0 ${1+"$@"} mean in Shell script?

查看:68
本文介绍了exec ${PERL-perl} -Sx $0 ${1+"$@"} 在 Shell 脚本中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是将包含 Shell 脚本、Perl 代码的 Shell 脚本转换为 Python.

I'm given a task to convert a shell script which contains Shell script, Perl code to Python.

我设法将 Perl 代码转换为 Python.

I managed to convert the Perl code to Python.

但是有一个我不明白的shell脚本语句.

But there is this shell script statement which I didn't understand.

#! /usr/bin/sh
exec ${PERL-perl} -Sx $0 ${1+"$@"}
#! /opt/tools/perl5/bin/perl
Some Perl code which I converted to Python

第二行是什么意思?

我知道 $0 将被评估为脚本名称.

I understood that $0 will be evaluated to the script name.

我假设 ${PERL-perl} 将评估机器上安装的任何 Perl 解释器(如果我错了,请纠正我,也请让我知道我该怎么做提及 Python 的类似内容).

And I'm assuming that ${PERL-perl} will evaluate to whatever Perl interpreter is installed on the machine (correct me if I'm wrong and also please let me know how do I mention the similar thing for Python).

有人能解释一下 exec 命令中剩余的参数是做什么的吗?

Can someone explain what those remaining parameters in that exec command do?

推荐答案

${PERL-perl} 是一个 参数扩展:如果未设置 PERL shell 变量,则使用 perl,否则使用PERL 的内容.(可以说,这应该是 ${PERL:-perl},因为如果 PERL 设置为空,则将使用空字符串.)

${PERL-perl} is a parameter expansion: if the PERL shell variable is unset, use perl, else use the content of PERL. (Arguably, this should be ${PERL:-perl}, because if PERL is set but empty, the empty string will be used.)

${1+"$@"} 代表如果设置了$1,则使用"$@"(所有位置参数),否则替换为 null".如果没有位置参数并扩展为单个参数而不是根本没有参数,则这对于会被 "$@" 混淆的旧 shell 来说是一个黑客.Bash 将只使用 "$@" 代替.

${1+"$@"} stands for "if $1 is set, use "$@" (all positional parameters), else substitute null". This is a hack for older shells that get confused by "$@" if there are no positional parameters and expand to a single parameter instead of none at all. Bash would work with just "$@" instead.

有关perl 的选项,请参阅perldoc perlrun.

For the options to perl, see perldoc perlrun.

这篇关于exec ${PERL-perl} -Sx $0 ${1+"$@"} 在 Shell 脚本中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆