【发布时间】:2021-02-25 17:11:56
【问题描述】:
使用以下时
read -r -d '' VAR <<EOF
first line
second line
EOF
echo "$VAR"
第一行的前导空格被修剪:
first line
second line
如何回显第一行中的前导空格并获得以下内容?
first line
second line
请注意,这是一个简化的示例,我需要使用here document!
【问题讨论】:
-
只需在
read之前添加IFS=:IFS= read ...。请注意,这也会保留最后一个换行符。 -
从文件或 here-document 读取没有什么不同。您的问题在这里有答案:Use Bash to read line by line and keep space