GithubHelp home page GithubHelp logo

pombredanne / sh-realpath Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mkropat/sh-realpath

0.0 1.0 0.0 12 KB

A portable, pure shell implementation of realpath

License: MIT License

Makefile 1.37% Shell 98.63%

sh-realpath's Introduction

sh-realpath

A portable, pure shell implementation of realpath

Copy the functions in realpath.sh into your shell script to avoid introducing a dependency on either realpath or readlink -f, since:

  • realpath does not come installed by default
  • readlink -f is not portable to OS-X (relevant man page)

Usage

$ source ./realpath.sh
$ realpath /proc/self
/proc/2772

Or we can get tricky:

$ cd /tmp
$ mkdir -p somedir/targetdir somedir/anotherdir
$ ln -s somedir somedirlink
$ ln -s somedir/anotherdir/../anotherlink somelink
$ ln -s targetdir/targetpath somedir/anotherlink
$ realpath .///somedirlink/././anotherdir/../../somelink
/tmp/somedir/targetdir/targetpath

API

Note: unlike realpath(1), these functions take no options; do not use -- to escape any arguments

Function Description
realpath PATH
| Resolve all symlinks to `PATH`, then output the canonicalized result
resolve_symlinks PATH
| If `PATH` is a symlink, follow it as many times as possible; output the path of the first non-symlink found
canonicalize_path PATH
| Output absolute path that `PATH` refers to, resolving any relative directories (`.`, `..`) in `PATH` and any symlinks in `PATH`'s ancestor directories

readlink Emulation

realpath.sh includes optional readlink emulation. It exposes a readlink function that calls the system readlink(1) if it exists. Otherwise it uses stat(1) to emulate the same functionality. In contrast to the functions in the previous section, you may pass -- as the first argument, since you may be calling the system readlink(1).

sh-realpath's People

Contributors

mkropat avatar nkovacs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.