我有一个多行变量,我只想要该变量的第一行。以下脚本演示了该问题:
#!/bin/bash
STRINGTEST="Onlygetthefirstline
butnotthesecond
orthethird"
echo " Take the first line and send to standard output:"
echo ${STRINGTEST%%$'\n'*}
# Output is as follows:
# Onlygetthefirstline
echo " Set the value of the variable to the first line of the variable:"
STRINGTEST=${STRINGTEST%%$'\n'*}
echo " Send the modified variable to standard output:"
echo $STRINGTEST
# Output is as follows:
# Onlygetthefirstline butnotthesecond orthethird
问题:为什么${STRINGTEST%%$'\n'*}在放置在echo命令后面时返回第一行,但是在分配之后放置空格时换行?
1
无法重现。它按预期对我有用。
—
2015年
也不能使用2.05b,3.1、3.2、4.0、4.1、4.2、4.3中的任何一个进行复制。听起来像是用户错误,例如尝试使用不支持
—
斯特凡Chazelas
$'...'bash 的shell运行它。