[Top][All Lists]

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

Re: Making a path absolute portably

From: Bob Friesenhahn
Subject: Re: Making a path absolute portably
Date: Wed, 10 Jul 2019 07:54:09 -0500 (CDT)
User-agent: Alpine 2.20 (GSO 67 2015-01-07)

On Wed, 10 Jul 2019, Sébastien Hinderer wrote:

Dear all,

I'd need to compute the absolute path of srcdir in a portable way (it's
okay if it includes symlinks).

Currently I use

abssrcdir=$(cd "${srcdir}"; echo $PWD)
which seems to work fine.

Is that considered portable enough?

It appears that $PWD is a shell extension, so I don't think so. Even the shell syntax being used to execute the external command is not very portable. In addition to that, if the cd "${srcdir}" fails, it would then capture the wrong directory.

This syntax is proven to be portable and reliable:

abssrcdir="`cd $srcdir && pwd`"

Bob Friesenhahn
GraphicsMagick Maintainer,
Public Key,

reply via email to

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