設定Ubuntu環境變數控制Putty視窗標題動態顯示 嗷,賣葛! 這次完了~ 關錯伺服器了,,, :( 經常會犯這樣的錯誤,因為案頭上開著N多個Putty遠端連線,它們都長成一個樣子,一不小心就會弄錯! 有什麼好辦法能讓我更好地區分它們呢? 下面給出好的解決方案 (以下情境執行Putty工具,使用root使用者遠程登入,SSH主機是 Ubuntu Server ) ● 使用不帶任何參數的 cd 命令,進入到 ~ 目錄下面 ● 由於 Ubuntu Server 13 的 ~/ 下沒有.bash_profile , 我們先用 touch .bash_profile 建立一個全新的 ● 用 vi 編輯之,輸入以下內容 --------------------------------------- # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startupprograms # PATH=$PATH:$HOME/bin # export PATH # add following statement to the END offile ~/.bash_profile # auto add env parameter $PROMPT_COMMANDwhen use non-Linux tty login by ssh. if [ "$SSH_CONNECTION" != '' ]; then export HOSTIP=`echo $SSH_CONNECTION |awk '{print $3}' |awk -F: '{if ($1== "") print $4; else print $1}'` export PROMPT_COMMAND='echo -ne"\033]0;${USER}@'$HOSTIP':[${HOSTNAME%%.*}]:${PWD/#$HOME/~} \007"' env |grep PROMPT_COMMAND # Set the DISPLAY env var for Xmanagerforward # export DISPLAY=`echo $SSH_CONNECTION |awk '{print $1}' |awk -F: '{if($1 == "") print $4; else print $1}'`:0.0 fi --------------------------------------- ● 上面的指令碼第一二句會執行一些環境參數設定的指令碼 ~/.bashrc,經研究,由於 Ubuntu 下的預設設定指令碼某些參數會與我們想要的效果衝突,所以要編輯並屏蔽掉部分內容。 用 vi 編輯 ~/.bashrc 將下面的兩段代碼給注釋屏蔽掉(將第一行最前加註釋符號 # ) --------------------------------------- 第一段: # set a fancy prompt (non-color, unless weknow we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac ---- 注釋後 ------- # case "$TERM" in # xterm-color) color_prompt=yes;; # esac 第二段: # If this is an xterm set the title touser@host:dir case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac --------------------------------------- 下面給出配置完畢後登入時自動顯示相關資訊的 enjoy !! :)