fork download
  1. f() # Wrapped in a function to verify all test cases.
  2. {
  3. [[ $2 = /* ]]||p=$1
  4. realpath -sm $p/$2
  5. unset p # Not required in a full program.
  6. }
  7.  
  8. f "/a/b/c" "d"
  9. f "/a/b/c/" "d"
  10. f "/a/b/c/" "d/"
  11. f "/a/b/c" "/d"
  12. f "/a/b/c" "/d/"
  13. f "/../a/b/c/" "d"
  14. f "/a/../b/c/" "d"
  15. f "/a/b/../c" "d"
  16. f "/a/b/c/.." "d"
  17. f "/a/b/c/" ".."
  18. f "/a/b/c" "../d"
  19. f "/a/b/c" "/../d"
  20. f "/a/b/c" ""
  21. f "/a/b/c" "."
  22. f "/a/b/c" "./d"
  23. f "/a/b/c" "/./d"
  24. f "/a/b/c" "d.txt"
  25. f "/a/b/c" "d."
  26. f "/a/b/c" ".txt"
  27. f "/a/b/c" ".txt/d"
  28. f "/a/b/." "./././."
  29. f "/direc" "tory"
  30. f "/a-_.b/" "__._-."
  31. f "/a/b" "../.."
  32. f "/a/b" "../../.."
  33. f "/a" "../../.."
  34. f "/" ""
  35. f "/" "a"
  36. f "/.." "a"
  37. f "/." ""
Success #stdin #stdout 0s 5080KB
stdin
Standard input is empty
stdout
/a/b/c/d
/a/b/c/d
/a/b/c/d
/d
/d
/a/b/c/d
/b/c/d
/a/c/d
/a/b/d
/a/b
/a/b/d
/d
/a/b/c
/a/b/c
/a/b/c/d
/d
/a/b/c/d.txt
/a/b/c/d.
/a/b/c/.txt
/a/b/c/.txt/d
/a/b
/direc/tory
/a-_.b/__._-.
/
/
/
/
/a
/a
/