Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/morgant/realpath
A portable bash implementation of `realpath`.
https://github.com/morgant/realpath
bash realpath
Last synced: 3 months ago
JSON representation
A portable bash implementation of `realpath`.
- Host: GitHub
- URL: https://github.com/morgant/realpath
- Owner: morgant
- Created: 2012-02-17T13:10:36.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2019-09-28T17:47:20.000Z (about 5 years ago)
- Last Synced: 2024-07-17T15:01:29.627Z (4 months ago)
- Topics: bash, realpath
- Language: Shell
- Homepage: http://www.makkintosshu.com/development/#realpath
- Size: 18.6 KB
- Stars: 18
- Watchers: 5
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
realpath
========by Morgan Aldridge
[![realpath on OpenHub](https://www.openhub.net/p/realpath/widgets/project_thin_badge.gif)](https://www.openhub.net/p/realpath) [![Build Status](https://travis-ci.com/morgant/realpath.svg?branch=master)](https://travis-ci.com/morgant/realpath) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=DBY3R8ARLDELE¤cy_code=USD&source=url)
OVERVIEW
--------A portable `realpath()` written in `bash`. The `realpath()` function in C (and many other languages) will return the absolute path when provided a relative path, but there's not an equivalent in `bash`. It's often suggested to use `readlink`, but while common under Linux, it's not available on many other platforms, esp. BSD-based platforms such as Mac OS X.
This is a simple implementation, originally based on [this solution](http://www.linuxquestions.org/questions/programming-9/bash-script-return-full-path-and-filename-680368/page2.html#post4239549), which uses `pwd`. Pass it one or more relative (or absolute, but that's somewhat pointless) file/directory paths and, if it exists, it'll output the absolute path to STDOUT. It'll also return 0 if successful or 1 if unsuccessful (also meaning the file/directory path doesn't exist). Naturally, it does not handle tildes (`~`) in paths as that should've been processed by the calling shell.
UNIT TESTS
----------Unit tests are implemented using [`roundup`](https://github.com/bmizerany/roundup). These tests can be run by executing `roundup` in the 'realpath' project directory (it'll automatically find and run the `realpath-test.sh` tests). If you discover any failing tests on your platform or any additional edge cases that should be tested, please let me know ASAP.
LICENSE
-------Copyright (c) 2012, Morgan Aldridge
All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.