写shell脚本的时候,有时候需要开启多个终端窗口,或者开启tmux窗口,分别执行不同的命令。
开启多个标签页分别执行1
#! /bin/bash
source ~/.bashrc
{
echo "create new teminal tab for demo1.sh"
gnome-terminal -t "demo1" -x bash -c "source ~/demo1.sh;exec bash"
}& # 后台运行
sleep 1 # 休眠 1 seconds
{
echo "create new teminal tab for demo2.sh"
gnome-terminal -t "demo2" -x bash -c "source ~/demo2.sh;exec bash;exec bash"
}&
sleep 1
exit # 执行此脚本的终端只是笔者开启其他几个终端的媒介,开完就不需要了,所以我关闭它,可以按照自己需求修改
开启tmux窗口2.3
#!/bin/bash
source ~/.bashrc
{
echo "Start a Tmux session."
tmux new -d -s mywork -n window0
## Split the window to 4 panes.
tmux split-window -h -t mywork:window0 # 垂直分割
tmux split-window -v -t mywork:window0.0 # 水平分割
tmux split-window -v -t mywork:window0.2 # 笔者在Mac上进行了测试,是从上到下再从左到右对每个窗口的idx计数
## Run the ROS programs sequentially.
tmux send -t mywork:window0.0 'echo "123"' ENTER
tmux send -t mywork:window0.1 'echo "Hello, world"' ENTER
tmux send -t mywork:window0.2 "ls" ENTER
tmux send -t mywork:window0.3 "pwd" ENTER
}
## Attach the Tmux session to the front.
tmux a -t mywork