replacestart
Unlike Bourne Again Shell (bash), POSIX shell does not have a native find/replace function for replacing a pattern at the start of a given string with another. Below is an implementation written in native POSIX shell that is:
Faster than piping to
awk
,sed
,perl
,python
,ruby
, or other langaugeCompatible with
bash
and all other POSIX-compliant shellsOptimized to use
${parameter/#pattern[/string]}
whenbash
is detected
Last updated