$$ 在shell中是什么意思? [英] What does $$ mean in the shell?

查看:63
本文介绍了$$ 在shell中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经读到过,在 shell 中为临时文件获取唯一文件名的一种方法是使用双美元符号 ($$).这确实会产生一个不时变化的数字……但是如果您重复调用它,它会返回相同的数字.(解决办法就是利用时间.)

I once read that one way to obtain a unique filename in a shell for temp files was to use a double dollar sign ($$). This does produce a number that varies from time to time... but if you call it repeatedly, it returns the same number. (The solution is to just use the time.)

我很想知道 $$ 究竟是什么,以及为什么建议将其作为生成唯一文件名的一种方式.

I am curious to know what $$ actually is, and why it would be suggested as a way to generate unique filenames.

推荐答案

在 Bash 中 $$ 是进程 ID,如注释中所述,将其用作临时文件名是不安全的各种原因.

In Bash $$ is the process ID, as noted in the comments it is not safe to use as a temp filename for a variety of reasons.

对于临时文件名,请使用 mktemp 命令.

For temporary file names, use the mktemp command.

这篇关于$$ 在shell中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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