What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

Skip to end of metadata
Go to start of metadata

Problem

Often you want to set the working directory for a bash script to the folder that the bash script is located in.

Solution

Add the following line at the beginning of your script:

#!/bin/bash

cd $(dirname $0)

References

  1. https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself