Quantcast
Viewing latest article 5
Browse Latest Browse All 46

Answer by Eugen Konkov for How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)?

The dogbaneanswer with the description what is coming on:

#! /bin/shecho "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"

Explanation:

  1. This script get relative path as argument "$1"
  2. Then we get dirname part of that path (you can pass either dir or file to this script): dirname "$1"
  3. Then we cd "$(dirname "$1") into this relative dir and get absolute path for it by running pwd shell command
  4. After that we append basename to absolute path: $(basename "$1")
  5. As final step we echo it

Viewing latest article 5
Browse Latest Browse All 46

Trending Articles