如何获得 Mac 的“.command"?运行shell脚本后自动退出的文件? [英] How do I get a Mac ".command" file to automatically quit after running a shell script?
问题描述
在我的 shell 脚本中,我的最后几行是:
In my shell script, my last lines are:
...
echo "$l" done
done
exit
我将终端首选项设置为当 shell 退出时:关闭窗口".在所有其他情况下,当我在终端中键入exit"或logout"时,窗口会关闭,但是对于这个.command"文件(我可以双击我的 shell 脚本文件,然后脚本运行),而不是关闭窗口,当文件的代码说退出"时,屏幕上显示的是:
I have Terminal preference set to "When the shell exits: Close the window". In all other cases, when I type "exit" or "logout", in Terminal, the window closes, but for this ".command" file (I can double-click on my shell script file, and the script runs), instead of closing the window, while the file's code says "exit", what shows on the screen is:
...
$l done
logout
[Process completed]
...并且窗口保持打开状态.有谁知道如何让 shell 脚本运行,然后在完成后自动退出终端窗口?
...and the window remains open. Does anyone know how to get a shell script to run, and then just automatically quit the Terminal window on completion?
谢谢!
推荐答案
我终于找到了答案.与 cobbal 的回答类似,它调用 AppleScript,但由于它是我打开的唯一窗口,并且我想将我的脚本作为快速打开和关闭操作运行,这种更粗暴的方法对我来说非常有用.
I was finally able to track down an answer to this. Similar to cobbal's answer, it invokes AppleScript, but since it's the only window that I'd have open, and I want to run my script as a quick open-and-close operation, this more brutish approach, works great for me.
在.command"脚本本身中,...将此行添加到您的脚本末尾"
Within the ".command" script itself, "...add this line to your script at the end"
osascript -e 'tell application "Terminal" to quit' &
exit
来源:http://forums.macosxhints.com/archive/index.php/t-2538.html
这篇关于如何获得 Mac 的“.command"?运行shell脚本后自动退出的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!