Combining parameter expansion forms

You cannot combine the preceding parameter expansion forms into one expansion; "${myvar:-foo#.ext}" does not do what you might hope. You could use a temporary variable instead, to run them one at a time:

#!/bin/bash
temp="${myvar:-foo}"
printf '%s\n' "${temp#.ext}"

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.