linux - 使用bash脚本打开多个终端窗口mac

标签 linux bash macos shell unix

#!/bin/bash
#!/usr/bin/python

read -p "Execute script:(y/n) " response
if [ "$response" = "y" ]; then
    echo -e "\n\nLoading....\n\n"

    for ((x = 0; x<5; x++))
    do
        echo -e "Open $x terminal\n\n"
        open -a Terminal.app
    done
fi

这只会打开一个新的终端窗口。如何打开 10 个新的终端窗口?

最佳答案

如果您想从 bash 脚本(或从命令行)打开 10 个新的终端窗口,请使用以下命令:

osascript -e 'tell application "Terminal"' -e 'repeat 10 times' -e 'do script ""' -e 'end repeat' -e 'end tell'

或者集成到您现有的代码中,尽管重新编码:

#!/bin/bash

shopt -s nocasematch
read -p " Execute script? (y/n): " response
if [[ $response == y ]]; then
    printf " Loading....\\n"
    for ((x = 0; x<10; x++)); do
        printf " Open %s Terminal\\n" $x
        osascript -e 'tell application "Terminal" to do script ""' >/dev/null
    done
fi
shopt -u nocasematch

它的输出将是:

$ ./codetest
 Execute script? (y/n): y
 Loading....
 Open 0 Terminal
 Open 1 Terminal
 Open 2 Terminal
 Open 3 Terminal
 Open 4 Terminal
 Open 5 Terminal
 Open 6 Terminal
 Open 7 Terminal
 Open 8 Terminal
 Open 9 Terminal
$ 

显示 10 个新的终端窗口,假设您没有设置在选项卡中打开新窗口。

关于linux - 使用bash脚本打开多个终端窗口mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48591219/

相关文章:

c++ - 自动生成我的c++代码的uml图

linux - ls -lth | awk '{printf.... 获取文件列表并添加标题

linux - 无法在 shell 脚本中打印公共(public) ip

bash - Unix 找到 : multiple -o and exec not working together

Linux shell : Changing decimal (float) separator from dot to comma

linux - 如何知道 tar 命令何时完成?

ruby-on-rails - 如何管理用户上传的文件?

linux - Buildroot - 建了一个文件系统,如何登录?引导挂起

c++ - 当 C++11 应用程序使用非 C++11 库时返回值损坏

c++ - ld:在 mac 上找不到体系结构 x86_64 的符号