Here’s how to grep for something and show only the matching part: # echo '${these}${are}${vars}' | grep -o -E '\${.*?}' ${these} ${are} ${vars}