coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

command for relative path


From: Peng Yu
Subject: command for relative path
Date: Sat, 12 Nov 2011 10:16:47 -0600

Hi,

coreutils can give abspaths ('readlink -f -e'). But I'm not able to
find a command for relative paths. I use the following python script
to do so. The drawback is that it is dependent on python (meaning it
is less portable). But I'm wondering if it is possible to add such a
command (or an option of a command) in coreutils.

~$ cat `which relpath.py `
#!/usr/bin/env python

import sys
import os

args = sys.argv

if len(args)-1 != 1 and len(args)-1 != 2:
  print >> sys.stderr, "Usage: %s <path> " %(os.path.basename(args[0]))
  print >> sys.stderr, "Usage: %s <path> <start>" %(os.path.basename(args[0]))
  sys.exit()

if len(args)-1 == 1:
  start='.'
else:
  start=args[2]

path=args[1]

print os.path.relpath(path, start)

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]