I wrote a script a while back that would do some simple install procedures in linux for people that don’t like the command line, but it seems that they are running the script from a location (such as root). So I have a solution in mind but trying to find out how to reference where the file is located.
Example.
I have a script called Install.sh in a folder /root/Server/Scripts/ which references itself by using the following:
SCRIPTSDIR=`pwd`
But I have come into problems with people running this script from root by doing sh Server/Scripts/Install.sh
How could I make SCRIPTS= something that references where the file is located, not where it is being run from?
Thanks, ask if you need more info!
Edit: All answers were good, I meant to put I needed absolute path.
You can get dir with
If your script is called with relative path, dirname will also return relative path. If you want to resolve it for some reason, you can do