如何获取Mac“.command”文件在运行shell脚本后自动退出? [英] How do I get a Mac ".command" file to automatically quit after running a shell script?

查看:1982
本文介绍了如何获取Mac“.command”文件在运行shell脚本后自动退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的shell脚本中,我的最后一行是:

  ... 
echo$ ldone
done

exit

我将终端首选项设置为当shell退出时:关闭窗口。在所有其他情况下,当我键入退出或退出,在终端窗口关闭,但对于这个.command文件(我可以双击我的shell脚本文件,脚本运行)关闭窗口,而文件的代码说退出,屏幕上显示的是:

  ... 
$ l done
logout

[Process completed]

...并且窗口保持打开。有没有人知道如何得到一个shell脚本运行,然后只是自动退出终端窗口完成后?



谢谢!

解决方案

我终于能够找到一个答案。类似cobbal的答案,它调用AppleScript,但由于它是我打开的唯一的窗口,我想运行我的脚本作为一个快速打开和关闭操作,这种更残酷的方法,对我很好。 / p>

在.command脚本本身中,...将此行添加到脚本结尾处

  osascript -e'告诉应用程序Terminal退出'& 
exit

SOURCE: http://forums.macosxhints.com/archive/index.php/t2538.html


In my shell script, my last lines are:

...
echo "$l" done
done

exit

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]

...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?

Thanks!

解决方案

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.

Within the ".command" script itself, "...add this line to your script at the end"

osascript -e 'tell application "Terminal" to quit' &
exit

SOURCE: http://forums.macosxhints.com/archive/index.php/t-2538.html

这篇关于如何获取Mac“.command”文件在运行shell脚本后自动退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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