端末を開くときにGNU画面を実行する

端末を開くときにGNU画面を実行する

開いているすべての端末がスクリーンセッションで開始されることを望みます。実際に私が望むのは、次のステップを実行することです。

1. win+enter (open terminal in i3wm)
2. $ screen

これを自動的に実行したいと思います。

[[ $TERM != "screen" ]] && screen

.bashrc。副作用として、多くのbashプロセスが生成されることがわかります(なぜ?)

alexhop+ 19307  0.0  0.0  28276  3016 pts/0    S+   11:20   0:00 screen
alexhop+ 19308  2.5  0.4  59272 33572 ?        Rs   11:20   0:00 SCREEN
alexhop+ 19309  0.2  0.0  24084  5516 pts/2    Ss+  11:20   0:00 /bin/bash
alexhop+ 19322  0.2  0.0  24084  5456 pts/3    Ss+  11:20   0:00 /bin/bash
alexhop+ 19338  0.2  0.0  24084  5316 pts/4    Ss+  11:20   0:00 /bin/bash
alexhop+ 19354  0.2  0.0  24084  5452 pts/5    Ss+  11:20   0:00 /bin/bash
alexhop+ 19370  0.2  0.0  24084  5388 pts/6    Ss+  11:20   0:00 /bin/bash
alexhop+ 19386  0.2  0.0  24084  5356 pts/7    Ss+  11:20   0:00 /bin/bash
alexhop+ 19402  0.2  0.0  24084  5452 pts/8    Ss+  11:20   0:00 /bin/bash
alexhop+ 19418  0.2  0.0  24084  5436 pts/9    Ss+  11:20   0:00 /bin/bash
alexhop+ 19434  0.2  0.0  24084  5456 pts/10   Ss+  11:20   0:00 /bin/bash
alexhop+ 19450  0.2  0.0  24084  5396 pts/11   Ss+  11:20   0:00 /bin/bash
alexhop+ 19466  0.2  0.0  24084  5388 pts/12   Ss+  11:20   0:00 /bin/bash
alexhop+ 19482  0.2  0.0  24084  5388 pts/13   Ss+  11:20   0:00 /bin/bash
alexhop+ 19498  0.2  0.0  24084  5388 pts/14   Ss+  11:20   0:00 /bin/bash
alexhop+ 19514  0.2  0.0  24084  5384 pts/15   Ss+  11:20   0:00 /bin/bash
alexhop+ 19530  0.2  0.0  24084  5512 pts/16   Ss+  11:20   0:00 /bin/bash
alexhop+ 19546  0.2  0.0  24084  5388 pts/17   Ss+  11:20   0:00 /bin/bash
alexhop+ 19562  0.0  0.0  24084  5384 pts/18   Ss+  11:20   0:00 /bin/bash
alexhop+ 19578  0.2  0.0  24084  5436 pts/19   Ss+  11:20   0:00 /bin/bash
alexhop+ 19594  0.2  0.0  24084  5388 pts/20   Ss+  11:20   0:00 /bin/bash
alexhop+ 19610  0.3  0.0  24084  5384 pts/21   Ss+  11:20   0:00 /bin/bash

どんな助けでも大変感謝します。

ホストシステム:Ubuntu 16.04.2 LTS

ベストアンサー1

これは、環境(など)の何かがTERM変数(たとえば、同様のもの)を設定しているため、ほぼ確実に.bashrc発生し/etc/profileますTERM=xterm

これにより[[ $TERM != "screen" ]]テストが true と評価され、別の画面インスタンスが起動します。

bashこれにより、画面内で$ SHELLが実行され、起動と起動screenscreen無限ループが発生しますbash

ところで、$TERM実行前に正しく設定しないと、実行中の端末を正しく使用する方法がわからなくなります。したがって、設定しないのは良い選択ではありません。screenscreen

シェルが内部で実行されているかどうかを検出するより良い方法がいくつかありますscreen。バラよりLinuxの「画面」内で動作しているかどうかはどうすればわかりますか?そして私が画面にあるかどうかはどうすればわかりますか?この質問に対する回答は、姉妹 Stack Exchange サイトで何度も要求されました。

最も簡単な方法は、おそらく$ STY変数が空であるかどうかをテストすることです。によると、man screenこの変数はscreen「代替ソケット名」を保持するように設定されています。

つまり、そうではありません:

[[ $TERM != "screen" ]] && screen

この試み:

[ -z "$STY" ] && screen    # test if $STY is empty

または:

[ -n "$STY" ] || screen    # test if $STY is NOT empty.

[[ .... ]]必要に応じてそれも使用できます。二重引用符を使用する必要がないことを除いて、違いはありません$STY。私の考えでは、これは悪い習慣であり、あなたの場合のために引用する必要があります。する二重引用符で囲む必要がある変数の数は、そうでないいくつかの特殊なケースよりはるかに多くなります。

おすすめ記事