When you run a bash
script, all of it's commands run in the directory where the script is invoked from, including pwd
. For example:
#!/bin/bash
pwd
If you run this from /whatever/path
, it will display /whatever/path
, no matter where the script is placed.
If you want to operate on files in the directory where you are running the script from, you can omit pwd
like this:
chmod +x D3GO
This will be interpreted as chmod +x /whatever/path/D3GO
if you run it from /whatever/path
, no matter where the script is actually placed.
To operate in the directory where the script is located, you can use the $BASH_SOURCE
variable. It is an array, and it's first element is the path to the script itself (i.e. /script/directory/myscript.sh
). You can combine this with the dirname
command to get just the directory:
chmod +x `dirname ${BASH_SOURCE[0]}`/D3GO
This will look for D3GO
in the directory where this script is placed instead of where it's invoked from. (Thanks to @muru for pointing out my mistake.)