-1

I'm trying to set the path for the PERL5LIB using a simple config file like this:

cat /Users/me/.local/bash.d/perl5lib_dirs | while read line
do
case ":$PERL5LIB:" in
  *:$line:*) :;;
  *) echo 'Adding path: '$line; PERL5LIB="$line:";;
esac
done

Apparently, since the loop is opened in a subshell, the value of the PERL5LIB variable is lost when the loop exits.

So how else can I accomplish this?

StevieD
  • 6,925
  • 2
  • 25
  • 45

2 Answers2

1

Rewrite the loop to read from the file with input redirection (thus avoiding the subshell):

while read line; do
    case ":$PERL5LIB:" in
        *:$line:*) :;;
        *) echo 'Adding path: '$line; PERL5LIB="$line:";;
    esac
done < /Users/me/.local/bash.d/perl5lib_dirs
P.P
  • 117,907
  • 20
  • 175
  • 238
0

Instead of running the game try sourcing the file.

for example abc.sh

abc=123
sh abc.sh
echo $abc

source abc.sh
echo $abc
123