bash将EOF重定向到变量 [英] bash redirecting EOF into variable

查看:225
本文介绍了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
)

这篇关于bash将EOF重定向到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆