Shell script good practice
Quite often I find myself writting shellscripts that have to deal with relative paths. The problem is that you can't assume that the user of your script is executing it from the scripts directory, so if you want something like this:
#!/bin/bash
./some/other/script.sh
to work from everywhere, you'll have to cd into your script's directory first:
#!/bin/bash
BASEDIR="$( cd "$( dirname "$0" )" && pwd )"
cd $BASEDIR
./some/other/script.sh
Written by Eric Marcos Pitarch
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#