calcular la ruta del directorio en relación con otra ruta con la ruta calculada en forma absoluta

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 ?


preguntado el 09 de marzo de 12 a las 13:03

2 Respuestas

You can probably just use this:

cd `dirname $0`/..
cd -

respondido 09 mar '12, 14:03

this does not give the absolute path. it gives something like /../config - John

Hm, in your question you didn't mention, that you are looking for absolute paths. - vanje

You actually said 'relative to another path' in the title. Please clarify. - eduardo ivanec

Thanks Eduardo. I just echoed the results of this and it looks like it is giving me what I need. I will incorporate this into my original script to set Java class path. - John

Si no BIN_DIR then you get the absolute path for your project directory with:

PROJECT_DIR=`readlink -f $BIN_DIR/..`

y entonces


respondido 09 mar '12, 14:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.