如何在 tmux 終端機上使用 bash 腳本?

如何在 tmux 終端機上使用 bash 腳本?

我使用 tmux 以及程式提供的快捷方式。我如何使用 shell 腳本執行多個選項,例如:檢查會話是否存在等。

答案1

此 shell 腳本將判斷會話(作為第一個參數提供)是否存在:

#!/bin/bash
tmux has-session -t $1 2> /dev/null

# Check the return value of previous command:
if [[ $? -eq 0 ]]; then
    echo "Session $1 exists"
else
    echo "Session $1 does not exist"
fi

相關內容