bash 是否 $! 在 shell 脚本中意味着什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18462916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does $! mean something in shell scripting
提问by pRAShANT
Does $!exists in bash/shell script, if yes, please inform for what it is used for. And why it gives blank when echo $!
is run on the command line?
是否$! 存在于 bash/shell 脚本中,如果是,请告知它的用途。为什么它echo $!
在命令行上运行时给出空白?
回答by anubhava
In addition to other answer, this echo
除了其他答案,这个回声
echo $!
Will print blank if you haven't yet run any process in backgroundin current shell. If you now run:
如果您尚未在当前 shell 的后台运行任何进程,则将打印为空白。如果你现在运行:
date &
echo $!
Then it will print something like (i.e. process id of last executed background process):
然后它将打印类似的内容(即上次执行的后台进程的进程 ID):
47833
回答by user000001
$!
is the PID of the last program your shell ran in the background
$!
是您的 shell 在后台运行的最后一个程序的 PID
回答by Ranjithkumar T
$! - shows last process ID which has started in background.
$! - 显示在后台启动的最后一个进程 ID。