从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?
推荐答案
带有xterm的选项1(完成后将自动关闭窗口):
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屋!