【发布时间】:2014-08-05 05:51:15
【问题描述】:
【问题讨论】:
-
echo a(echo b)c...见fishshell.com/docs/current/index.html#expand
标签: interpolation fish
【问题讨论】:
echo a(echo b)c...见fishshell.com/docs/current/index.html#expand
标签: interpolation fish
echo a(echo b)c
如果有引号,则必须退出:
echo "a"(echo b)"c"
如果您的子命令可能有换行符,从 fish 2.3 开始,您必须保存并恢复 $IFS:
set -l IFS
echo "a"(cat ~/file.txt)"c"
set -e IFS
最终string 将能够处理这种情况。
【讨论】:
echo -e "a\nb" > x 然后 bash echo "$(cat x)" 做正确的事情,而 fish echo (cat x) 会将换行符转换为空格(相当于不带引号的 bash echo $(cat x))。
IFS设置为空之外,还有没有其他办法?
string collect 现在可用于避免换行符拆分。用法示例:echo (cat x | string collect)