2014-09-29 45 views
0

例如,我登錄時運行tmux attach -d。 .bashrc,.profile之類的東西似乎在後臺運行它?我想在登錄後立即看到在終端中運行的操作。我嘗試在運行命令的.ssh中將command =「echo 1」條目添加到authorized_keys中,並將我註銷,這不是我想要的。如何在登錄時運行命令並使其顯示在控制檯中?

+0

你試過 1>/dev/tty並將其放入你的〜/ .bashrc或〜/ .bash_profile – 2014-09-29 17:08:23

回答

1

要運行的東西開始登錄shell運行時,馬上爲.bashrc部分,把這些作爲最後一個行:

if shopt -q login_shell; then 
    exec tmux attach -d 
    # run exit if you want to be logged out if the exec fails, otherwise omit 
    exit 
fi 

然而,這將意味着你將不會被倒入一個實際bash殼,並且當tmux退出時,您將被註銷。

+0

謝謝,但這對我不起作用,因爲每次打開新shell都會執行。所以如果我在tmux中打開另一個shell,它會打開另一個tmux。 tmux中的tmux很難與 – BreezyChick89 2014-09-29 17:24:10

+0

一起工作我更新了檢查[登錄shell](http://unix.stackexchange.com/a/26782)​​的答案,因此後續的非登錄shell將不會運行該命令。 – zerodiff 2014-09-29 17:32:56

+0

如果[[-o login]];結束了使用這個 ;然後 tmux attach -d fi – BreezyChick89 2014-09-30 18:33:34

相關問題