如何判斷是否正在tty下使用screen/tmux - Linux

Una avatar
By Una
at 2011-09-21T00:17

Table of Contents

我通常是用"tty"這個指令判斷是否正在tty下

例如

1. 在tty(1~6)時(假設在tty1)

user@local_host:~$ tty
/dev/tty/1 => tty


2. 在x11中使用gnome-termial時

user@local_host:~$ tty
/dev/pts/7 => pts

3. 用putty遠端到遠端Linux伺服器時

user@remote_host:~$ tty
/dev/pts/10 => pts

4. 在gnome-terminal中使用screen/tmux時

user@local_host:~$ tty
/dev/pts/8 => pts

不過

5. 在tty(1~6)中使用screen/tmux時

user@local_host:~$ tty
/dev/pts/8 => 恩...好希望它顯示的是tty = =


我希望在情況5.中, 能判斷出"我正在tty使用screen/tmux"

然而此時"tty"這個指令似乎就沒用了

請問有甚麼其他判斷方法嗎

(除了印出$TERM之外

因為不論是在x或tty中attach screen, $TERM的內容都是一樣的

還有我不希望手動調整$TERM的內容)

--
Tags: Linux

All Comments

Erin avatar
By Erin
at 2011-09-23T19:56
$WINDOW
Puput avatar
By Puput
at 2011-09-26T11:48
alias tmux='export TMUXTTY=`tty`; tmux'
Puput avatar
By Puput
at 2011-09-27T23:54
不知道上述作法是否符合需求.
Quanna avatar
By Quanna
at 2011-10-01T13:38
你現在是需要在被控制程式中能取得目前控制之screen/tmux
Edward Lewis avatar
By Edward Lewis
at 2011-10-02T23:08
嗎?被控制程式一定是shell或可能是任何程式?
Connor avatar
By Connor
at 2011-10-07T08:35
我的shell指的是交談式的shell.
Todd Johnson avatar
By Todd Johnson
at 2011-10-10T08:22
我大概懂了. 我的想法如下:有沒有X11,可以判斷 $DISPLAY
Eartha avatar
By Eartha
at 2011-10-12T04:04
你主要的問題應該是本來是在非 tty 下,後來又被tty的tmux
Xanthe avatar
By Xanthe
at 2011-10-13T06:19
attach(或相反情況,這裏我假設若前後條件一樣是沒問題)
Vanessa avatar
By Vanessa
at 2011-10-13T12:30
這裏產生的問題是新的tmux環境變數無法被舊的shell繼承
Mason avatar
By Mason
at 2011-10-16T00:46
#1EUR5Ips 有版友提到IPC(行程間通訊)做法,我認為還有個問
題,就是shell不知道哪個新的tmux才是新主人. 這點我倒是有
Donna avatar
By Donna
at 2011-10-18T16:44
個第一時間想法,還沒去試,方法如下:把版友的方法的檔名
的差異部分,改用 tmux 的 pid,然後 shell 去 /proc 目錄
Cara avatar
By Cara
at 2011-10-19T05:09
搜尋某個 pid 的 fd 目錄下,有開啟相同的 pts 的就是自己
的新主人. 表達得有點亂,以上希望你能看懂,也希望能有幫助
Zenobia avatar
By Zenobia
at 2011-10-20T05:56
突然想到: 反過來看$DISPLAY 是不是在xserver下?
Isla avatar
By Isla
at 2011-10-24T10:44
我不知道screen/tmux的差別 不過用$STY來判斷應該不會重覆
裡面也是有pid的資訊

BBS字型

Frederic avatar
By Frederic
at 2011-09-20T23:52
新版 1.6 昨天release 加上參數-s 80x24就可以正常瀏覽一些不支援長螢幕的bbs站了 ※ 引述《scp958630 (日立安)》之銘言: : 標題: Re: [問題] BBS字型 : 時間: Thu Aug 4 11:19:00 2011 : : 以下是適用於每個BBS站 : 不須依賴 ...

Vmware的centos 6 桌面沒東西

Agnes avatar
By Agnes
at 2011-09-20T21:03
您好~ 今天利用vmware安裝centos 6 後 桌面本來一切正常 後來安裝virtuso時安裝了一些xwindow的字型後 桌面就沒東西了,按滑鼠右鍵也沒反應 狀況的網址如下: http://imageshack.us/photo/my-images/534/problemeu.png/ 不 ...

如何讓ls -l的結果依照數字遞增排序

Ingrid avatar
By Ingrid
at 2011-09-20T16:24
應該是個很基本的問題 不過man ls好像沒寫 google也沒找到atat 假設原本ls -l的結果(檔名那個column)是這樣: 10 11 1 2 3 4 5 6 7 8 9 有辦法變成這樣嗎 : 1 2 3 4 5 6 7 8 9 10 11 - ...

誤改檔名後如何快速改回來

Selena avatar
By Selena
at 2011-09-20T15:31
有時候手殘會發生這種事 原本想要打這樣: useratlocal_host:~$ scp a_file_with_long_filename useratremote_host:path_to_put_the_file 卻不小心打成這樣, 誤改了檔名: useratlocal_host:~$ mv a ...

mplayer編譯問題

Frederic avatar
By Frederic
at 2011-09-20T07:40
各位好: 我使用ubuntu系統!! 以下是我編譯的過程,但始終無法成功撥放任何的影片或聲音 可以成功編譯,但文字模式下的mplayer就是沒影沒音 是哪邊沒設定到或是少安裝甚麼嗎? 1.官方下載原始碼 http://www.mplayerhq.hu/MPlayer/rel ...