gpt4 book ai didi

linux - 如何将 Linux 终端配置为在输出 "\n"时仅换行(而不是回车)?

转载 作者:太空宇宙 更新时间:2023-11-04 10:33:06 24 4
gpt4 key购买 nike

当我运行一个向终端输出“\n”的程序时,我想预先配置终端(可能通过 stty)不执行回车,而只将光标向下移动一行。实际上将其视为换行,而不是执行回车。

例如,如果程序打印“123\n456”,我希望看到:

123
456

当然,我目前看到:

123
456

最佳答案

man stty 说:

   * [-]onlcr
translate newline to carriage return-newline

所以我们可以关闭它,打印一些东西,然后再打开它:

$ stty -onlcr; printf '\rfoo\nbar\r\n'; stty onlcr
foo
bar

关于linux - 如何将 Linux 终端配置为在输出 "\n"时仅换行(而不是回车)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38860411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com