从 shell 打开终端并执行命令 [英] Open Terminal from shell and execute commands
问题描述
我很懒所以我想写一个shell脚本来打开我的开发环境.我设置了两个命令 dev
和 dev-startup
.当我运行 dev/directory/path
时,它应该在 /directory/path
处打开一个新的终端窗口并执行 dev-startup
.
I am lazy so I want to write a shell script to open my dev environment. I setup two commands dev
and dev-startup
. When I run dev /directory/path
it should open a new terminal window at /directory/path
and execute dev-startup
.
我不确定如何在特定目录下打开终端窗口,然后运行最终命令来运行我需要设置环境的工具.
I'm not sure how to open the terminal window at a specific directory and then run a final command to run the tools I need to setup the environment.
我正在运行 OSX,所以 AppleScript 可能是答案?
I'm running OSX, so maybe AppleScript is the answer?
推荐答案
Option 1 with xterm(完成后会自动关闭窗口):
Option 1 with xterm (will automatically close the window when completed):
xterm -e "cd /tmp/; watch 'pwd;date'"
MacOS 终端的选项 2:
Option 2 with MacOS terminal:
osascript -e 'tell application "Terminal" to do script "cd /tmp;pwd"'
这篇关于从 shell 打开终端并执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!