Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve parent directory of script

Tags:

bash

shell

unix

I'm working on an uninstaller script to delete the parent folder where the script is installed.

/usr/local/Myapplication/Uninstaller/uninstall.sh

So uninstall.sh has to do this:

rm- rf /usr/local/Myapplication

I can retrieve the folder where uninstall resides

SYMLINKS=$(readlink -f "$0")
UNINSTALL_PATH=$(dirname "$SYMLINKS")

But I'm still unsure of the pretty way to get the parent path. I thought of using sed to demove the "Uninstaller" part of this path, but is there an elegant way to get the path to Myapplication folder to delete it?

Thank you

like image 335
MangO_O Avatar asked Nov 25 '13 14:11

MangO_O


1 Answers

I put this answer as comment at 2018. But since I got a great feedback about the effectiveness of the solution, I will share it here as well :

# dir of script 
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
# parent dir of that dir
PARENT_DIRECTORY="${DIR%/*}"
like image 192
Abdennour TOUMI Avatar answered Sep 20 '22 15:09

Abdennour TOUMI