One solution would be to use Python:

```
python -c 'import os; print os.path.expanduser(os.path.realpath("/tmp"))'
```

That line will normalize the path, including expanding '~/' (but will not do 
any other variable substitutions). It however does not ensure that that path 
exists. If you want that, then:

```
python -c 'from __future__ import print_function; import os; bob = 
os.path.expanduser(os.path.realpath("/tmp")); exit("path does not exist: %s" % 
bob) if not os.path.exists(bob) else print(bob)'
```

By switching in `os.path.isfile` you can also make sure that the item at the 
end of the chain is a file (`isdir` is also available).


> On Jun 5, 2017, at 12:50 AM, Jean-Christophe Helary 
> <[email protected]> wrote:
> 
> The readlink command on OSX is not the same as the Linux command.
> 
> Specifically, the linux version has a -f flag that does:
> 
> -f, --canonicalize
> canonicalize by following every symlink in every component of the given name 
> recursively; all but the last component must exist
> 
> I'm checking the OSX version and I'm not finding an equivalent. Is there a 
> workaround for this ?

_______________________________________________
MacOSX-talk mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-talk
  • readlink... Jean-Christophe Helary
    • Re: readlink... Karl Kuehn

Reply via email to