1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-12-28 15:39:44 +01:00

Fix abs_dirname

There are no tests for this unfortunately and it is copied into two
places.

Ref: https://github.com/rbenv/rbenv/pull/868
This commit is contained in:
Daniel Hahler 2017-06-23 23:49:00 +02:00
parent 03608115df
commit 87ae363144
2 changed files with 24 additions and 14 deletions

View File

@ -6,17 +6,22 @@ resolve_link() {
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
local save_cwd="$PWD"
local dir name
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
while [[ -n "$path" ]]; do
dir="${path%/*}"
if [[ "$dir" != "$path" ]]; then
cd "$dir"
name="${path##*/}"
else
name="$path"
fi
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
echo "$PWD"
cd "$save_cwd"
}
PREFIX="$1"

View File

@ -31,17 +31,22 @@ resolve_link() {
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
local save_cwd="$PWD"
local dir name
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
while [[ -n "$path" ]]; do
dir="${path%/*}"
if [[ "$dir" != "$path" ]]; then
cd "$dir"
name="${path##*/}"
else
name="$path"
fi
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
echo "$PWD"
cd "$save_cwd"
}
expand_path() {