Adam K Dean

Set cwd to script directory

Published on 22 January 2020 at 22:53 by Adam

Perhaps this will be the smallest snippet I've ever posted, and yet, one of the most useful. If you have a script that you want to be able to invoke from anywhere and yet not worry about relative paths, use this.

cd "${0%/*}"

This works great when you have a script in a subdirectory that builds a dockerfile, and you want it to look for the relative Dockerfile.



This post was first published on 22 January 2020 at 22:53. It was filed under archive with tags linux, bash, shell.