find the script's own folder

Inside a script, find the folder the script is in, to reach files next to it.

  • shell
  • development

Steps

  1. dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

    the script's folder, as a full path

  2. cd "$dir"

    work from there

  3. echo "$(basename "$0")"

    the script's own name

  4. realpath "$0"

    its full path, links resolved

Commands used

  • dirname
  • realpath

Each has a page in lore: lore dirname opens it.