Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bash script get absolute path

I’m not familiar with bash scripting. In my app, I have three folders. Frontend, backend, and script are the three folders. My bash script is contained within the script. This is the structure of my app Image. I’d like to retrieve absolute path variables (frontend and backend) from my script. I’m not sure what to do. I was successful in obtaining the script path folder. My objective is to obtain an absolute route from a script.

#!/bin/sh

root_path="$( cd  "$(dirname "$0")" >/dev/null 2>&1 || exit ; pwd -P )"
#frontend_path=
#backend_path=

echo "Getting absolute path ${root_path}"

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Adding /.. after the output of dirname should do the trick to get you the root path:

root_path="$( cd  "$(dirname "$0")/.." >/dev/null 2>&1 || exit ; pwd -P )"

From that on, you can just add /frontend / /backend to get the other paths:

frontend_path="$root_path/frontend"
backend_path="$root_path/backend"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading