Вопрос

hey guys I'm wondering if there is a smart way to look back before a period in bash

file='foo'/bar/styles.css?ver=1.4.2

ext=$(echo ${file} | gawk -F  "?" '{print$1}')
echo "${ext##*.}" # css

Seems like I should be able to do this all in my expansion somehow?

Это было полезно?

Решение

Don't think you can do it with just one bash expansion statement (unless they can be nested somehow), works fine with two though

$ start=${file%%\?*}; echo ${start##*.}
css
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top