sh 脚本中的 ${Tmp0} 是什么?

发布于 2024-12-11 06:53:01 字数 216 浏览 0 评论 0原文

在 shell 脚本中,我发现了以下代码行:

rm -f "${Tmp0}"

这是脚本中的第一行之一,我不熟悉 Tmp0 变量。它是到特定内容的 shell 标准映射吗?我做了一些谷歌搜索,但似乎找不到好的解释。

我怀疑这是脚本的先前版本的剩余部分(不需要查看整个内容,它是无关紧要的),因为我在其中的其他任何地方都看不到对此变量的任何引用。

In a shell script, I found the following line of code:

rm -f "${Tmp0}"

It is one of the first lines in the script, and I'm not familiar with the Tmp0 variable. Is it a shell standard mapping to something specific? I did some Google searches and I can't seem to find good explanation.

I suspect this is a leftover from a previous version of the script (no need to see the whole thing, it's irrelevant), since I can't see any reference to this variable anywhere else in it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我ぃ本無心為│何有愛 2024-12-18 06:53:01

它没有预定义的含义,但这并不意味着它没有用。如果有人在调用此脚本之前导出此变量,它将删除定义的文件。此外,如果此脚本source是另一个文件,则该变量可能会在那里定义。

无论如何,如果这两个条件都不成立,那么它确实可能是一个剩余物。

It doesn't have predefined meaning, but that doesn't mean it's useless. If someone exports this variable before calling this script it will delete the defined file. Also if this script sources another file, this variable might be defined there.

Anyway, if none of the two conditions hold true, then it indeed might be a leftover.

余厌 2024-12-18 06:53:01

变量 ${Tmp0} 没有标准含义。

通常,在此之前会有一个对 Tmp0 的赋值,例如:

Tmp0="${TMPDIR:-/tmp}/tmp.$.0"               # Generate a file name
rm -f "${Tmp0}"                               # Ensure file does not exist!
trap 'rm -f "${Tmp0}"; exit 1' 0 1 2 3 13 15  # Ensure file is cleaned up on early exit

...code using $Tmp0 as a temporary file...

rm -f "${Tmp0}"   # Clean up
trap 0            # Allow exit status other than 1
exit $status      # Exit with specified status

如果赋值不可见,那么它可能是某种剩余的碎片,或者某人没有非常仔细地选择环境变量命名方案(以及对文件的有些可疑的处理;无条件删除文件的脚本很少长期流行)。

There is no standard meaning for the variable ${Tmp0}.

Usually, there'd be an assignment to Tmp0 before that, such as:

Tmp0="${TMPDIR:-/tmp}/tmp.$.0"               # Generate a file name
rm -f "${Tmp0}"                               # Ensure file does not exist!
trap 'rm -f "${Tmp0}"; exit 1' 0 1 2 3 13 15  # Ensure file is cleaned up on early exit

...code using $Tmp0 as a temporary file...

rm -f "${Tmp0}"   # Clean up
trap 0            # Allow exit status other than 1
exit $status      # Exit with specified status

If the assignment isn't visible, then it is probably leftover debris of some sort, or someone's not very careful chosen environment variable naming scheme (and somewhat dubious handling of files; scripts that go around deleting files unconditionally are seldom popular for long).

一曲爱恨情仇 2024-12-18 06:53:01

如果您是这个意思,那么这不是 shell 的硬编码变量。

您可以在代码中添加一个简单的调试来打印变量的内容,该信息可能会为您提供一些有关其用途的线索:

echo "DEBUG: Tmp0 content is: ${Tmp0}"
rm -f "${Tmp0}" 

That's not a hard-coded variable of the shell, if that's what you meant.

You can add a simple debug to the code to print the content of the variable and that information might give you some clues on it's purpose:

echo "DEBUG: Tmp0 content is: ${Tmp0}"
rm -f "${Tmp0}" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文