Sample Header Ad - 728x90

Using bash, resolve absolute path to relative path

1 vote
1 answer
2117 views
Say I have this simple bash script: #!/usr/bin/env bash file="$1"; if [ -z "$file" ]; then echo "Must pass relative file path as the first argument."; fi git_root=git rev-parse --show-toplevel; # => need to resolve file from an absolute path to relative path, relative to git root git diff HEAD:"$file" remotes/origin/dev:"$file" If I pass an absolute path to this script, it needs to be able to handle it. What is the canonical way to do that? To check if it's an absolute file path, do we just check if the first character is "/"?
Asked by Alexander Mills (10744 rep)
Sep 27, 2018, 07:53 PM
Last activity: Sep 27, 2018, 08:06 PM