expansion

Bash Replace first match

Replaces the first match using shell pattern syntax; the original variable is unchanged.

Formal Syntax & Structure

bash syntaxbash
${p/pattern/string}

Return Value

shell expansion result

Replaces the first match using shell pattern syntax; the original variable is unchanged.

Working Example

Example Snippetbash
p=a-aprintf '%s\n' "${p/a/b}"
Bash Reference