Reputation: 887
I have this directory structure for an application: bin, config, lib.
In bin directory I have a bash script. I want to be able to set variables in the bash script for config and lib directories based on the location of the script file in the bin directory. I can get the directory name for script that is executing by doing:
BIN_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
My question is: How can I calculate the diectory paths for config and lib directories based on BIN_DIR ?
Thanks.
Upvotes: 1
Views: 465
Reputation: 10383
If you have BIN_DIR
then you get the absolute path for your project directory with:
PROJECT_DIR=`readlink -f $BIN_DIR/..`
and then
CONFIG_DIR=$PROJECT_DIR/config
LIB_DIR=$PROJECT_DIR/lib
Upvotes: 2
Reputation: 11862
You can probably just use this:
cd `dirname $0`/..
BASE_DIR=`pwd`
cd -
BIN_DIR=${BASE_DIR}/bin
CONFIG_DIR=${BASE_DIR}/config
LIB_DIR=${BASE_DIR}/lib
Upvotes: 3