From: Kenny McCormack on
In article <i22pp8$qc$2(a)news.xmission.com>,
Kenny McCormack <gazelle(a)shell.xmission.com> wrote:
....
>Re: #3 above, I seem to remember that Linux did have something like
>that, but (obviously) I can't remember any details. In any event, a
>Linux-specific solution would be more than welcome.

And, indeed, realpath(1) [and the related library calls realpath(3) and
canonicalize_file_name(3)] seem to be the ticket.

So, there ya go...

--
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy of the church so decides."

- Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -

From: Ben Finney on
gazelle(a)shell.xmission.com (Kenny McCormack) writes:

> 1) It won't work right if I happen to invoke the alias with an
> absolute path. Because then, the app would get something like:
> /path/to/here/path/from/root/file
> So, it would be nice to plug this small hole.
>
> 2) I'm just curious if there is a better, more built-in way to do
> this - some shell tool (something along the lines of basename)
> maybe.

I'm not aware of one in standard Unix.

Can you count on having 'readlink(1)' available? That would allow you
to:

infile="$(readlink --canonicalize-missing $filepath_arg)"

--
\ “It is an interesting and demonstrable fact, that all children |
`\ are atheists and were religion not inculcated into their minds, |
_o__) they would remain so.” —Ernestine Rose |
Ben Finney
From: Wayne on
On 7/20/2010 12:33 AM, Ben Finney wrote:
> gazelle(a)shell.xmission.com (Kenny McCormack) writes:
>
>> 1) It won't work right if I happen to invoke the alias with an
>> absolute path. Because then, the app would get something like:
>> /path/to/here/path/from/root/file
>> So, it would be nice to plug this small hole.
>>
>> 2) I'm just curious if there is a better, more built-in way to do
>> this - some shell tool (something along the lines of basename)
>> maybe.
>
> I'm not aware of one in standard Unix.
>
> Can you count on having 'readlink(1)' available? That would allow you
> to:
>
> infile="$(readlink --canonicalize-missing $filepath_arg)"
>

Linux systems have readlink(1) available, but all POSIX systems have
readlink(2). You just need to write a tiny C program for this.

--
Wayne
From: Kenny McCormack on
In article <4c45cd69$0$15279$9a6e19ea(a)unlimited.newshosting.com>,
Wayne <nospan(a)all.invalid> wrote:
>On 7/20/2010 12:33 AM, Ben Finney wrote:
>> gazelle(a)shell.xmission.com (Kenny McCormack) writes:
>>
>>> 1) It won't work right if I happen to invoke the alias with an
>>> absolute path. Because then, the app would get something like:
>>> /path/to/here/path/from/root/file
>>> So, it would be nice to plug this small hole.
>>>
>>> 2) I'm just curious if there is a better, more built-in way to do
>>> this - some shell tool (something along the lines of basename)
>>> maybe.
>>
>> I'm not aware of one in standard Unix.
>>
>> Can you count on having 'readlink(1)' available? That would allow you
>> to:
>>
>> infile="$(readlink --canonicalize-missing $filepath_arg)"
>>
>
>Linux systems have readlink(1) available, but all POSIX systems have
>readlink(2). You just need to write a tiny C program for this.

The problem is that the readlink syscall only deals with, surprise!
surprise! symbolic links. It is not equivalent to realpath(3).

In fact, it is a small subset of realpath(3).

realpath(3) is pretty much equivalent to INT 21/AH=60

--
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.

CLC in a nutshell.

From: Seebs on
On 2010-07-20, Wayne <nospan(a)all.invalid> wrote:
> Linux systems have readlink(1) available, but all POSIX systems have
> readlink(2). You just need to write a tiny C program for this.

It is not a tiny program.

Well, "tiny" is relative. It is not completely trivial to correctly
generate a "fixed" absolute path including and taking account of all
symbolic links. It's much easier to implement
x=$(cd $relpath; /bin/pwd)

Issues you face in trying to resolve symbolic links:
* both relative and absolute links
* .. in part of the path
* . in part of the path
* symbolic link loops

The one that usually gets people is variants of
foo/bar//./../baz

Which is, it turns out, "foo/baz". There are various ways to streamline
this.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!