Skip to content

Instantly share code, notes, and snippets.

@tueda
Last active December 23, 2015 17:39
Show Gist options
  • Save tueda/6669998 to your computer and use it in GitHub Desktop.
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.
#! /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