#!/usr/bin/env bash s="a-b-c" # ${var/pattern/replacement} replaces only the first match echo "${s/-/_}"
${s/old/new} replaces the first occurrence