[winswitch] readlink (via python realpath)
Antoine Martin
antoine at devloop.org.uk
Thu Aug 14 13:01:16 BST 2014
On 14/08/14 15:07, Scott-Fleming, Ian wrote:
> A -
>
>>>
>>> read link properly resolves symbolic links to the true pathname. It
>>> also gets the full pathname if the file is found via the search path.
>> That doesn't work when used directly:
>>
> Ouch.
> indeed. you are right. hadn’t tried it on a regular file. (read
> link -f works properly in regular linux for any pathname…why can’t Mac
> OS X do the same?) There doesn’t seem to be a direct OS X bash
> solution equivalent to linux’s “read link -f”.
>
> (And you’re right about needing quotes for filenames with spaces.
> always forget that people who don’t know better put spaces in their
> filenames…)
>
> The best I’ve found via google is the following. Relies on python
> being present, but your package requires python, so should be valid in
> your script:
That's a bit different though, we ship our own python and this script is
required to find it..
>
> true_name=$(python -c 'import os,sys;print
> os.path.realpath(sys.argv[1])' "$0")
> exe_name=$( basename $true_name)
> full_path=$(dirname $true_name )
>
In any case, I would much rather not have to rely on finding and running
python, and use shell if-else instead.
Surely we don't need a python interpreter to figure out which path we're at?
I know this OSX, but come on!
(snip)
> BTW, if you stay with your solution: “pwd -P” might be preferable to
> “pwd” (-P canonicalizes the path to cur dir if it contains any
> symbolic links, but won’t canonicalize the filename if its a link).
That bit is now merged:
http://xpra.org/trac/changeset/7281
Thanks
Antoine
More information about the shifter-users
mailing list