Skip to content

Use a more portable method of detecting the current script's directory #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2022

Conversation

jthurne
Copy link
Member

@jthurne jthurne commented Feb 6, 2022

The method used before relied on GNU readlink's -e CLI flag, which isn't supported on the version of readlink shipped with BSD and MacOs.

Finding the current script's directory is tricky business. There are many StackOverflow questioins on this very topic, and many opinions on the "best" way to do it. The solution in this commit was carefully selected after reviewing many sources of information on the topic. Below are references to the most useful sources:

The method used before relied on GNU readlink's -e CLI flag, which isn't
supported on the version of readlink shipped with BSD and MacOs.

Finding the current script's directory is tricky business. There are many
StackOverflow questioins on this very topic, and many opinions on the "best"
way to do it. The solution in this commit was carefully selected after
reviewing many sources of information on the topic. Below are references to the
most useful sources:

  * [Reliable way for a Bash script to get the full path to itself [duplicate]](https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself):
    * This is the best question on Stack Overflow because the question contains a
    specific set of requiremewnts (which are very close to our own requirements).
    In particular, [this answer](https://stackoverflow.com/a/9107028/106189) is helpful.

  * [Determining the Location of Your Script in Bash](https://www.binaryphile.com/bash/2020/01/12/determining-the-location-of-your-script-in-bash.html):
    * This is an excellent blog post which walks through and explains the solution in detail.
@etiennestuder
Copy link
Member

Thanks, @jthurne .

@jthurne jthurne force-pushed the jhurne/portable-script-dir branch from f7b124e to 8bcff46 Compare February 6, 2022 12:51
@etiennestuder
Copy link
Member

@jthurne I cannot review it technically but I'm sure this is an improvement if you raise it. Feel free to merge this.

Just curious: was this PR motivated by someone reporting an issue?

@jthurne jthurne merged commit 13dd79b into main Feb 7, 2022
@jthurne jthurne deleted the jhurne/portable-script-dir branch February 7, 2022 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants