Skip to content

Latest commit

 

History

History
67 lines (42 loc) · 1.38 KB

realpath-check.md

File metadata and controls

67 lines (42 loc) · 1.38 KB

src/realpath.bash

Resolve the real absolute path and check for its existence.

Overview

realpath-check calls realpath to resolve a relative path or a symbolic link to its real absolute path. It then checks for its existence and returns an error code if the path does not exists.

Index

realpath-check

Resolve a real absolute path and for check its existence. If the file does not exists, display an error message and return error. Print its absolute real path on stdout if found.

Example

source "${BASH_SOURCE[0]%/*}/libs/biapy-bashlings/src/realpath-check.bash"
file_path="../relative/path"
if file_realpath="$( realpath-check "${file_path}" )"; then
  echo "File found. processing..."
else
  exit 1
fi

Options

  • -q | --quiet

    Disable the error message.

  • -e | --exit

    Enable exiting on failure.

Arguments

  • $1 (string): A path to resolve.

Exit codes

  • 0: If successful.
  • 1: If the path does not exists, an argument is missing or more than one argument given.

Output on stdout

  • The resolved absolute path.

Output on stderr

  • Error if the argument is missing or more than one argument is given.
  • Error if the path does not exist

See also