bug-bash
[Top][All Lists]
Advanced

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

Re: equivalent of Linux readlink -f in pure bash?


From: Bob Proulx
Subject: Re: equivalent of Linux readlink -f in pure bash?
Date: Mon, 8 Aug 2011 21:36:43 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

Jon Seymour wrote:
> readlink -f will fully resolve links in the path itself (rather than
> link at the end of the path), which was the behaviour I needed.

Ah, yes, well, as you could tell that was just a partial solution
anyway.

> It seems cd -P does most of what I need for directories and so
> handling things other than directories is a small tweak on that.

You might try cd'ing there and then using pwd -P to get the canonical
directory name.  I am thinking something like this:

  #!/bin/sh
  p="$1"
  dir=$(dirname "$p")
  base=$(basename "$p")
  physdir=$(cd "$dir"; pwd -P)
  realpath=$(cd "$dir"; ls -l "$base" | awk '{print$NF}')
  echo "$physdir/$realpath" | sed 's|//*|/|g'
  exit 0

Again, another very quick and partial solution.  But perhaps something
good enough just the same.

Bob



reply via email to

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