Skip to content

Instantly share code, notes, and snippets.

@JacobJohansen
Created March 24, 2022 13:08
Show Gist options
  • Save JacobJohansen/11fc2bc32f998df360fb50d67be6a287 to your computer and use it in GitHub Desktop.
Save JacobJohansen/11fc2bc32f998df360fb50d67be6a287 to your computer and use it in GitHub Desktop.
Provides a solid way for scripts to run from no matter where they're executed from, even when simlinked for all nix systems with perl. most systems don't have readlink
#!/bin/sh
relative_dir=`perl -e 'use Cwd "realpath";$pwd = realpath(shift); $pwd =~ s/\/[^\/]*$//; print $pwd' $0`
cd $relative_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment