Repository

Looks good to me!

User Tools

Site Tools


Action disabled: diff
kb:lang:scripting:bash:start

Bash

Changelog

  • 2025-08-17: Init

Some tips and tricks.

Filepath manipulation

Remove extension from filepath, accounting for:

  • Presence of directory slash
  • Spaces in filenames and directories
  • Removes only one extension for multi-extension files
  • Treats dotfiles as regular files
  • POSIX-compatible
# 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

kb/lang/scripting/bash/start.txt · Last modified: 6 days ago (17 August 2025) by justin