sách gpt4 ai đã đi

linux - PuTTY:Linux 窗口 - 如何在函数执行期间更新窗口标题?

In lại 作者:太空宇宙 更新时间:2023-11-04 10:22:19 27 4
mua khóa gpt4 Nike

我正在通过 PuTTY 从 Windows 10 PC 访问 Linux 机器。我通过如下设置 $PS1 将 PuTTY (Bash) 窗口标题设置为“$PWD”:

PS1=\[\033]0;\w\007\]\[\033[1;33m\][\w]$\[\033[0m\]

这很好用——每当我在 shell 中更改目录时,标题都会立即更新:

Enter image description here

但是,如果我在函数中更改目录(如下所示),则在函数完成后标题才会更新:

function func() {
cd /share/testing_area/runtests ;
python Script.py;
}

Enter image description here Enter image description here

有没有办法让标题在脚本期间更新?

答案:脚本的最终版本:

function func() {
cd /share/testing_area/runtests
export PS1="\[\e[1;33m\][\w]$\[\e[0m\]" # Remove title spec from $PS1
echo -ne "\e]2;$PWD\a" # Set title to current values (uses $PWD as \w doesn't work for echo
python Script.py;
export PS1="\[\033]0;\w\007\]\[\033[1;33m\][\w]$\[\033[0m\]" # Re-add title spec to $PS1
}

1 Câu trả lời

您正在使用提示中的 PuTTY 自动标题更改标题。不幸的是,提示通常会在您的提示再次可见后生效,这意味着不会在您的函数或脚本结束之前生效。

如果您想动态更改标题,我会推荐 this solution instead .

关于linux - PuTTY:Linux 窗口 - 如何在函数执行期间更新窗口标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43342150/

27 4 0
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com