Bash

Changelog

  • 2025-08-17: Init

Some tips and tricks.

Filepath manipulation

Remove extension from filepath, accounting for:

# Remove extension '$filepath' -> '$stempath'
case "$filepath" in
  */* ) 
    # 'filepath' is a path under some directory
    dirpath="${filepath%/*}"
    filename="${filepath##*/}"
    stem="${filename%.*}"
    test -z "$stem" && stem="$filename"
    stempath="$dirpath/$stem"
    ;;
  *)
    # otherwise, filepath is the filename itself
    stempath="${filepath%.*}"
    test -z "$stempath" && stempath="$filepath"
    ;;
esac

Output