<commit_before># sh-realpath

*A portable, pure shell implementation of realpath*

Copy the functions in [realpath.sh](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](https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man1/readlink.1.html))

## 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.  Any arguments
**should not** be escaped with `--`.

Function                 | Description
-------------------------|--------------
`realpath PATH`          | Resolve all symlinks to `PATH`, then output the canonicalized result
`resolve_symlinks PATH`  | Follow symlink that `PATH` points to; repat as many time as necessary to find a non-symlink, then output it
`canonicalize_path PATH` | Output absolute path that `PATH` refers to, resolving any relative directories (`.`, `..`) in `PATH` and any symlinks in `PATH`'s parent directories

## readlink(1) Portability

**sh-realpath** has a hard dependency on the `readlink` command.

It should be noted that `readlink(1)` is not included in the [POSIX
Standard](https://shellhaters.heroku.com/posix).  However, the command is
included in GNU coreutils, FreeBSD, OS-X, and probably elsewhere, so it is
reasonably portable.

If for some reason you need to support systems that do not have the `readlink`
command, one workaround is to define a shell function to replace it using the
`ls` command.  For implementation hints, see [this<commit_msg>Improve README copy<commit_after># sh-realpath

*A portable, pure shell implementation of realpath*

Copy the functions in [realpath.sh](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](https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man1/readlink.1.html))

## 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(1) Portability

**sh-realpath** has a hard dependency on the `readlink` command.

It should be noted that `readlink(1)` is not included in the [POSIX
Standard](https://shellhaters.heroku.com/posix).  However, it is
included in GNU coreutils, FreeBSD, OS-X, and probably elsewhere, so it is
reasonably portable.

If for some reason you need to support systems that do not have the `readlink`
command installed, one workaround is to define a shell function called `readlink`
that wraps the output of `ls -l`.  For implementation hints, see [this
{'fraction_non_alphanumeric': 0.11989167897587395, 'fraction_numerical': 0.004431314623338257, 'mean_word_length': 3.4746696035242293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5718697', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1178, 'n_words': 464}