Remove substring matching pattern both in the beginning and the end of the variable

Well, you can’t nest ${var%}/${var#} operations, so you’ll have to use temporary variable.

Like here:

var="http://whatever/score/"
temp_var="${var#http://}"
echo "${temp_var%/score/}"

Alternatively, you can use regular expressions with (for example) sed:

some_variable="$( echo "$var" | sed -e 's#^http://##; s#/score/$##' )"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)