Home > Blockchain >  bash get first element before the first integer of a variable
bash get first element before the first integer of a variable

Time:02-23

I want to get the first element before the first integer of a variable, For example, I have this variable:

FILE=normalize-component-0.0.3-SNAPSHOT-jar-with-dependencies-package-58.jar

And I want to get the application name which is the name "normalize-component" in that case that always comes before an integer.

Take in mind that the application name can always change but the structure will always be:

{application_name}-{digit}-{*}-jar-with-dependencies-package-{digit}.jar

desired output:

APP_NAME=normalize-component

CodePudding user response:

Use parameter expansion in bash:

$ FILE="normalize-component-0.0.3-SNAPSHOT-jar-with-dependencies-package-58.jar"

$ echo "${FILE%%-[[:digit:]]*}"
normalize-component
  • Related