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
kb/lang/scripting/bash/start.txt · Last modified: 3 months ago (17 August 2025) by justin
                
                