Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know I can source FILE or . FILE a file in Bash, but for some reason I cannot get it to load in the file. I keep seeing "No such file or directory" errors in the console.

Here's the directory structure

/bin/ (file including the config)

I may re-structure this anyways, but for now, I think it is what it is. I'm attempting to include the config file like this:

source ../

Neither one of those actually works. Any ideas?

share|improve this question
Maybe there's a better way to get the path, relative to the script being executed? – Will Ashworth Mar 6 '14 at 17:38
You're in the wrong directory? – Michael Hampton Mar 6 '14 at 17:46
Well that's kind of the issue. Theoretically the can be executed from just about anywhere on the system. It doesn't really matter where you execute long as you can supply a correct path to the script to execute it. That's my thinking anyways. – Will Ashworth Mar 6 '14 at 17:49
This works... if ../ is relative to $PWD. You might want to look at this for a lead in the right direction. – Aaron Copley Mar 6 '14 at 17:51
That totally helped out. Thank you Aaron! – Will Ashworth Mar 6 '14 at 18:11

Aaron's response totally helped out. This is the solution that ended up working for me.

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPTDIR/../;
share|improve this answer
Glad to help. I really didn't have time to answer it myself. – Aaron Copley Mar 6 '14 at 18:20
Yeah, getting the path from within the script was an all-around win. That worked beautifully! – Will Ashworth Mar 6 '14 at 21:18
Please see BashFAQ/028. – Dennis Williamson Mar 7 '14 at 2:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.