making vars in bash script accessible from shell

Price, Erik eprice at ptc.com
Thu Nov 7 15:19:06 EST 2002


Hi,

I know there's some hardcore shell heads on this list, so I was hoping I could solicit some assistance here... 

I've isolated the problem to an inability to make a variable declaration accessible outside of the script.  It's almost as if there were a bash form of "use strict" going on that was keeping my variables within the scope of the script.  If I try to echo $newPWD, I get nothing -- but I can see that $newPWD is getting set in the script.  I've tried "export newPWD", which doesn't do anything either.

This is obviously some fundamental rule of variable scope in bash that I just don't know, so can someone set me right?

Bash v. 2.02 on Solaris.

Thanks,
Erik



#!/usr/local/bin/bash
#(yes, that's the location of bash on my system)

# How many characters of the $PWD should be kept
pwdmaxlen=30

# indicator that there has been directory truncation
trunc_symbol="..."
if [ ${#PWD} -gt $pwdmaxlen ]
then
        pwdoffset=$(( ${#PWD} - $pwdmaxlen ))
        newPWD="${trunc_symbol}${PWD:${pwdoffset}:${pwdmaxlen}}"
else
        newPWD=${PWD}
fi



More information about the gnhlug-discuss mailing list