bash将EOF重定向到变量

问题描述:

这是我的文件perl5lib.sh:

this is my file perl5lib.sh:

export PERL5LIB=`cat |tr '\n' ':'`<<EOF
/home/vul/repository/projects/implatform/daemon/trunk/lib/
/home/vul/repository/projects/platformlib/tool/trunk/cpan_lib
/home/projects/libtrololo

我想以...开头文件

. perl5lib.sh

填充PERL5LIB变量,但挂起.怎么了? 我的目标是在文件末尾保留文件夹名称,因此我可以简单地添加新内容:

to populate PERL5LIB variable, but it hangs. What is wrong? my goal is to left folder names at the end of file, so I can add new simply:

echo dirname >> myscript

我已经尝试过,export PERL5LIB=$(echo blabla)cat<<EOF都可以单独工作,但不能一起工作.

I have tried and export PERL5LIB=$(echo blabla) and cat<<EOF both work separately, but not together.

===================解决方案=========================== ==

=================== THE SOLUTION ============================

function fun
{
     export PERL5LIB=`cat|tr '\n' ':'`
}
fun<<EOF
/dir1/lib
/dir2/lib
/dir3/lib
EOF

cat在这里没有用.在子外壳中提供EOF:

cat is useless here. Provide EOF inside the subshell:

#! /bin/bash
export PERL5LIB=$(tr '\n' ':'<<EOF
/home/vul/repository/projects/implatform/daemon/trunk/lib/
/home/vul/repository/projects/platformlib/tool/trunk/cpan_lib
/home/projects/libtrololo
EOF
)