[英]bash shell script heredoc issues
i want run a bash shell script like this: 我想运行这样的bash shell脚本:
while read file;
在读取文件时;
do
做
echo $file;
done << eof
完成<< eof
$(ls)
$(ls)
eof;`
eof;`
it work well in a sample .sh file. 它在示例.sh文件中运行良好。 but when put this in a function like:
但是当把它放在像这样的函数中时:
function {
while read file;
do
echo $file;
done << eof
$(ls)
eof;
}
it not work for me. 这对我不起作用。
i dont know how to fix it now. 我现在不知道该如何解决。
try un-indenting your eof: 尝试缩进您的eof:
function {
while read file;
do
echo $file;
done << eof
$(ls)
eof;
}
不要缩进您的Heredoc,并且您的eof
标记不应包含尾随的分号
In bash : use <<-TERMINATION
if you want it to ignore whitespaces before the TERMINATION
string (but if you prefer compatibility, use <<TERMINATION
and have TERMINATION
alone on a line, and starting at the first column. If the trailing ;
is a problem too, put it on the next line (or put a : ;
if you prefer) 在bash:使用
<<-TERMINATION
,如果你希望它忽略空格之前TERMINATION
字符串(但如果你喜欢的兼容性,使用<<TERMINATION
,并有TERMINATION
单独位于一行,并在第一列开始。如果尾随;
是也有问题,将其放在下一行(或如果需要,则添加: ;
)
And give a name to your function : function myfunction { ... }
(or, more compatible : myfunction () { ... }
) 并给您的函数起一个名字:
function myfunction { ... }
(或更兼容的是: myfunction () { ... }
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.