简体   繁体   中英

Mac: gnome-terminal equivalent for shell script

I am trying to run a shell script in a MAC terminal. I want to open a new terminal window that will execute the script separate from the program that is running. In Fedora, there is a gnome-terminal command which lets me execute a script in another terminal shell.

Does anyone know an equivalent on MAX OSX and how to use it?

For example say I have a script crazy.sh and I want to call this from a program that is executing but in a separate terminal from the one which is currently executing the program.

I like DigitalTrauma's answer but I found for my use, this worked better

open -a Terminal.app crazy.sh

Thanks for the answers.

One way to do it is to use an xterm instead of a terminal window:

xterm -e crazy.sh

If you want the xterm to stay open after the script completes, use the -hold option to xterm.


But if you really need to do this in a terminal, you can do it with applescript:

tell application "Terminal"
    activate
    tell application "System Events" to keystroke "n" using command down
    repeat while contents of selected tab of window 1 starts with linefeed
        delay 0.1
    end repeat
    do script "crazy.sh" in window 1 -- make sure the path to your script is right
end tell

(Credit to the answer here https://superuser.com/questions/466619/open-new-terminal-tab-and-execute-script )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM