Re: exporting variable from script 1 and using these variables in script 2



John Smith <wleung7@xxxxxxxxx> wrote:
I have dir1/script1.sh that contains:

#!/bin/bash

HOMEDIR=/development/home
UPLOADDIR=/applications/app1

export HOMEDIR
export UPLOADDIR

I have dir2/script2.sh that uses dir1/script1.sh as follows:

#!/bin/bash

. ~/dir1/script1.sh
^^^
I don't think your cgi-scripts will run under the same account you tested
this script with.

~ (== $HOME) will expand to something totally different when run from
the webserver (depending on the Apache installation nobody, www, webservd
or something else). You should either use an absolute path here or you
could evaluate $0 to get the directory script2.sh (btw bash != sh, so you
shouldn't name them sh, but that is just convention) is located. A check
if script1.sh can be found is also good practice.

where=`dirname $0`
inc="${where}/../dir1/script1.sh"
if [ -f "${inc}" ]; then
. ${where}/../dir2/script1.sh
else
echo "XXX"
exit 1
fi


You should also really look in Apache's error_log file...

Hope your cgi-script doesn't accept any input.


--
Daniel
.