How To: Run shell scripts containing relative paths from anywhere

Have you ever had the problem that you want to run a script but because it handles relative paths it depends on the directory it’s called from? Well, today I learned about a shell function that helps with that, called dirname. It can be fed a path and will return it with the last non-slash component and trailing slash removed. So to refer to the location a script sits in you can do simply:...

December 8, 2023 · 1 min