f()                     # Wrapped in a function to verify all test cases.
{
	[[ $2 = /* ]]||p=$1
	realpath -sm $p/$2
	unset p             # Not required in a full program.
}

f "/a/b/c"      "d"
f "/a/b/c/"     "d"
f "/a/b/c/"     "d/"
f "/a/b/c"      "/d"
f "/a/b/c"      "/d/"
f "/../a/b/c/"  "d"
f "/a/../b/c/"  "d"
f "/a/b/../c"   "d"
f "/a/b/c/.."   "d"
f "/a/b/c/"     ".."
f "/a/b/c"      "../d"
f "/a/b/c"      "/../d"
f "/a/b/c"      ""
f "/a/b/c"      "."
f "/a/b/c"      "./d"
f "/a/b/c"      "/./d"
f "/a/b/c"      "d.txt"
f "/a/b/c"      "d."
f "/a/b/c"      ".txt"
f "/a/b/c"      ".txt/d"
f "/a/b/."      "./././."
f "/direc"      "tory"
f "/a-_.b/"     "__._-."
f "/a/b"        "../.."
f "/a/b"        "../../.."
f "/a"          "../../.."
f "/"           ""
f "/"           "a"
f "/.."         "a"
f "/."          ""