Last active
December 23, 2015 17:39
-
-
Save tueda/6669998 to your computer and use it in GitHub Desktop.
abs_dirname is similar to dirname but prints the directory name in the absolute path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Prints the absolute path to the directory containing the given path. | |
# The directory must exist. | |
abs_dirname() {( | |
cd "`dirname \"$1\"`" && pwd | |
)} | |
# Examples | |
mkdir tmp_ABC | |
dirname /usr/bin/ | |
abs_dirname /usr/bin/ | |
dirname . | |
abs_dirname . | |
dirname ../1 | |
abs_dirname ../1 | |
dirname ./tmp_ABC/1 | |
abs_dirname ./tmp_ABC/1 | |
rmdir tmp_ABC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment