gpt4 book ai didi

string - 如何在 Bash 命令替换结束时禁止或删除换行符?

转载 作者:行者123 更新时间:2023-11-29 09:39:58 25 4
gpt4 key购买 nike

如何禁止或删除 Bash 末尾的换行符 command substitution

比如我有

echo "$(python --version) and more text"

如何获取

Python 2.7.10 and more text

不是

Python 2.7.10
and more text

最佳答案

庆典 command substitution syntax already removes trailing newlines .您需要做的就是重定向到标准输出:

$ echo "$(python --version) and more text"
Python 2.7.8
and more text
$ echo "$(python --version 2>&1) and more text"
Python 2.7.8 and more text

关于string - 如何在 Bash 命令替换结束时禁止或删除换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33504379/

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