Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash通过mutt以文本形式发送变量,而不使用echo或printf_Bash - Fatal编程技术网

Bash通过mutt以文本形式发送变量,而不使用echo或printf

Bash通过mutt以文本形式发送变量,而不使用echo或printf,bash,Bash,我有以下问题: 我有一个文件,其中包含一个列表,我想格式化并作为电子邮件发送。 因为变量包含换行符,所以我不能使用echo将变量导入mutt。我尝试了printf,但它只打印变量的第一行。我还希望避免创建新文件,因为此脚本在敏感位置运行 以下是代码供参考: TEST=hello TEST=$TEST$'\n'`cat file.txt` echo $TEST | mutt -s "test" email@domain.com 给我 hello line1 line2 line3 line4 l

我有以下问题: 我有一个文件,其中包含一个列表,我想格式化并作为电子邮件发送。 因为变量包含换行符,所以我不能使用echo将变量导入mutt。我尝试了printf,但它只打印变量的第一行。我还希望避免创建新文件,因为此脚本在敏感位置运行

以下是代码供参考:

TEST=hello
TEST=$TEST$'\n'`cat file.txt`
echo $TEST | mutt -s "test" email@domain.com
给我

hello line1 line2 line3 line4 line5...
hello

给我

hello line1 line2 line3 line4 line5...
hello

正如Etan所指出的,将变量去引用放在引号内,例如
echo“$TEST”
告诉echo不要使用换行符。

尝试
echo“$TEST”
printf%s\\n“$TEST”
以避免shell剥离换行符。是的。成功了。谢谢。我的问题和你的问题唯一的共同点是echo和printf。核心问题可能是相同的,但症状却大不相同。因此,在搜索时,我无法将两者联系起来。症状没有区别。症状是“我的空白消失了”。是的,问题本身并不相同,但问题(和解决方案)是相同的。不,你发现这个问题根本不可能。