| 1 | #!@BASH@ |
|---|
| 2 | # |
|---|
| 3 | # Copyright (c) 2008, Christopher Cowart and contributors |
|---|
| 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # Redistribution and use in source and binary forms, with or without |
|---|
| 7 | # modification, are permitted provided that the following conditions |
|---|
| 8 | # are met: |
|---|
| 9 | # * Redistributions of source code must retain the above copyright |
|---|
| 10 | # notice, this list of conditions and the following disclaimer. |
|---|
| 11 | # * Redistributions in binary form must reproduce the above copyright |
|---|
| 12 | # notice, this list of conditions and the following disclaimer in the |
|---|
| 13 | # documentation and/or other materials provided with the distribution. |
|---|
| 14 | # |
|---|
| 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 16 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 17 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 18 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 19 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 20 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
|---|
| 21 | # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|---|
| 22 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|---|
| 23 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 24 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 25 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | # |
|---|
| 27 | # $Id$ |
|---|
| 28 | # |
|---|
| 29 | # This script takes an argument and prints to STDOUT the absolute pathname |
|---|
| 30 | # of that argument. |
|---|
| 31 | # |
|---|
| 32 | # Example: abspath ../postfix.conf |
|---|
| 33 | |
|---|
| 34 | function abspath { |
|---|
| 35 | local file="$1" |
|---|
| 36 | local dir |
|---|
| 37 | if [ -d $file ] ; then |
|---|
| 38 | dir=`cd $file >/dev/null; echo \$PWD` |
|---|
| 39 | echo "$dir" |
|---|
| 40 | else |
|---|
| 41 | realpath="$file" |
|---|
| 42 | imagpath="" |
|---|
| 43 | while ! [ -d $realpath ]; do |
|---|
| 44 | imagpath="${imagpath}/${realpath##*/}" |
|---|
| 45 | realpath="${realpath%/*}" |
|---|
| 46 | done |
|---|
| 47 | echo "$(abspath $realpath)${imagpath}" |
|---|
| 48 | fi |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | abspath $1 |
|---|
| 52 | |
|---|