2

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

I want to start file as

. perl5lib.sh

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

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

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

function do the trick!

function fun
{
     export PERL5LIB=`cat|tr '\n' ':'`
}
fun<<EOF
/dir1/lib
/dir2/lib
/dir3/lib
EOF
xoid
  • 1,114
  • 1
  • 10
  • 24
  • This should not work. It should complain about a missing here-document terminator. And there's a useless `cat` as well. – Jens Oct 12 '12 at 13:13
  • your "function do the trick!" section spawns two extra child processes – bobah Oct 12 '12 at 15:30
  • 1
    Please remove the "does the trick" section and accept one of the answers (or make it an answer and accept it). – einpoklum Apr 19 '13 at 06:27

3 Answers3

4

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
)
choroba
  • 231,213
  • 25
  • 204
  • 289
4

What you call "EOF" can be googled as Here Document. Here Document can only be used to feed the standard input of a command. The below example does what you want without spawning child processes

#!/bin/bash

multilineconcat=
while read line; do
  #echo $line
  multilineconcat+=$line
  multilineconcat+=":"
done << EOF
path1
path2
EOF

echo $multilineconcat
bobah
  • 18,364
  • 2
  • 37
  • 70
2

Isn't it waiting for the EOF in your heredoc ?

I'd expect you to say

$ mycommand <<EOF
input1
input2
...
EOF

Note that EOF isn't a magic keyword. It's just a marker, and could be anything (ABC etc.). It indicates the end-of-file, but people simply write EOF as convention.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440