相关:如何获取当前终端名称?
但我只想要当前终端的 ID,例如,当tty返回时/dev/pts/11我只想打印11。
我们的想法是在 shell 提示符中在我的文件中的变量\u中的用户名后面添加此信息:PS1.bashrc
想要的结果:username11@localhost:~$
目前我有:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u$(tty)@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
Run Code Online (Sandbox Code Playgroud)
这使:username/dev/pts/11@localhost:~$
Ste*_*itt 15
使用\\l,它给出shell\xe2\x80\x99s 终端设备名称的基本名称:
PS1=\'${debian_chroot:+($debian_chroot)}\\[\\033[01;32m\\]\\u\\l@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ \'\nRun Code Online (Sandbox Code Playgroud)\n这和逃跑\\l getty类似。