3

I have a script which sets some environment variable to paths:

export VAR1=/home/xyz/DIR_IN_WHICH_THIS_FILE_EXISTS

export VAR2=$VAR1/abc/qwe

...

Can I use something to get the DIR_IN_WHICH_THIS_FILE_EXISTS so that if I run this script from anywhere(any path) in the machine, it would set the same values to VAR1 depend on in which directory the script exists?

Please help

1
  • It's not really clear to me what you are trying to do. Can you give an example of what you want to achieve? Thanks.
    – qbi
    Oct 25, 2013 at 13:04

2 Answers 2

5

I think that you are interested about the path of the running script. If so, you should use dirname:

export VAR1=$(dirname "${BASH_SOURCE[0]}")

where ${BASH_SOURCE[0]} refers to the name of the curent running script.

0

If I understand you well, I think you need the backticked output of pwd (print working directory)

Thus try:

export VAR1=`pwd`

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .