2 # ---------------------------------------------------------------------------
3 # Multi-Phasic Applications: SquirrelJME
4 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 # Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
6 # ---------------------------------------------------------------------------
7 # SquirrelJME is under the GNU General Public License v3, or later.
8 # For more information see license.txt.
9 # ---------------------------------------------------------------------------
10 # DESCRIPTION: Calculates the absolute path of a file
15 # path is absolute, just needs . and .. removed
16 if echo "$__check" |
grep '^\/' > /dev
/null
20 # Get relative path from PWD
22 __yuck
="$(pwd)/$__check"
25 # Split path by slashes and handle each line
26 # Need file due to argument stuff.
29 echo "$__yuck" |
tr '/' '\n' |
while read __seg
31 # If this segment is ".", ignore it
32 # Also ignore blank segments too
33 if [ "$__seg" = "." ] ||
[ -z "$__seg" ]
37 # If this is .., remove the topmost path element
38 elif [ "$__seg" = ".." ]
40 sed 's/\/[^/]*$//g' < /tmp
/$$.abs
> /tmp
/$$.abs2
41 mv /tmp
/$$.abs2
/tmp
/$$.abs
43 # Otherwise append to path
45 __part
="$(cat "/tmp
/$$.abs
")"
46 printf '%s/%s' "$__part" "$__seg" > /tmp
/$$.abs
50 # Blank result ends in /
51 __result
="$(cat /tmp/$$.abs)"