#!/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/