-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabspath
37 lines (35 loc) · 1.11 KB
/
abspath
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! .desc:
# Convert a relative pathname into an absolute pathname
#! .params:
# <"$1"> - path
#! .uses.var:
# <PWD> $ - environment variable;
# absolute pathname of the current working directory
#! .gives:
# <"$_path"> - string;
# [absolute <$1>]
#! .rc:
# (0) success
#! .ec:
# (255) bad input
#.
abspath() {
[ "$1" ] || exit 255
# Use $PWD (absolute pathname of the current working directory) to convert
# a relative path into an absolute one if it's not already.
#
# For more information, refer to:
# > "POSIX.1-2024, Volume: Base Definitions, Section: Definitions,
# Subsection: Absolute Pathname".
# > "POSIX.1-2024, Volume: Base Definitions, Section: Definitions,
# Subsection: Relative Pathname".
# > "POSIX.1-2024, Volume: Base Definitions, Section: Environment
# Variables, Subsection: Environment Variable Definition".
# > "POSIX.1-2024, Volume: Base Definitions, Section: Environment
# Variables, Subsection: Other Environment Variables".
case "$1" in
'/'*) _path="$1" ;;
*) _path="${PWD%/}/$1" ;;
esac
return 0
}