本文介绍了执行tclsh时需要什么shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/bin/sh
# A Tcl comment, whose contents don't matter \
exec tclsh "$0" "$@"

为什么要在这里调用shell (#!/bin/sh)

why should we invoke shell here (#!/bin/sh) .

我们可以直接调用 tclsh (#!/usr/sbin/tclsh) .让我们假设 tclsh 在 sbin 目录中.

We can directly invoke the tclsh (#!/usr/sbin/tclsh) . Let us Assume tclsh is in sbin directoey.

为什么我们首先调用 shell,然后在 shell 中再次调用 tclsh 解释器.

Why we are First calling the shell and again inside the shell we are calling tclsh interpreter .

为什么人们更喜欢使用这些 (#!/bin/sh , exec tclsh "$0" "$@") .我们不能执行 tclsh direclty 吗?

why people prefer to use these (#!/bin/sh , exec tclsh "$0" "$@") . Can't we execute tclsh direclty ?

推荐答案

出于一个原因,在某些系统上,您可以严格地锁定可以在 shebang 行中运行的可执行文件.换句话说,它可能会拒绝运行任何不在 /bin 中的东西.或者,如果您的管理员特别残暴,他们可能会试图强迫每个人都使用 zsh :-)

For one reason, on some systems, you can rigidly lock down what executables can be run in a shebang line. In other words, it may refuse to run anything not in /bin. Or maybe, if your administrators are particularly sadistic, they may try to force everyone to use zsh :-)

其次,这将根据您当前的路径设置运行 tclsh.如果您希望不同的用户使用不同版本的 TCL 运行它,这将非常宝贵.否则,您必须在 shebang 行上给出一个绝对路径,这在不同的系统上可能会有所不同(尽管 /usr/bin/env 也可以解决这个问题).

Secondly, this will run tclsh based on your current path settings. That's invaluable if you want different users to run it with different versions of TCL. Otherwise, you have to give an absolute path on the shebang line and this may be different on different systems (although /usr/bin/env can also take care of that).

在提交之前使用更新版本的 tclsh 测试脚本也很方便.例如,您可以在当前最新的 Debian (7.1) 下使用 tclsh 8.5,同时通过在 $HOME/staging/tcl86 中构建它并更改路径使目录出现在 usr 之前来测试 TCL 8.6/bin.

It's also handy to test the scripts with more recent versions of tclsh before committing to them. For example, you can have tclsh 8.5 under the current latest Debian (7.1) while testing TCL 8.6 by building it in $HOME/staging/tcl86 and changing your path so that directory appears before usr/bin.

在我的系统上(它被锁定到我的规格但没有进一步),脚本:

On my system (which is locked down to my specs but no further), the script:

#!/usr/bin/env tclsh
puts $tcl_version

工作正常,输出:

8.5

脚本也是:

#!/usr/bin/tclsh
puts $tcl_version

尽管如前所述,它与 tclsh系统 版本相关,而不是我路径中的第一个版本.

although, as mentioned, it's tied to the system version of tclsh rather than the first one on my path.

而且,是的,您可以很好地理解论点,根据以下记录:

And, yes, you can get at the arguments just fine, as per the following transcript:

pax> cat qq.tcsh
#!/usr/bin/tclsh
puts $argc
puts $argv

pax> qq.tcsh my name is pax
4
my name is pax

这篇关于执行tclsh时需要什么shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 02:26