1

Given a string "this-is-a-test" I want to get the last part after the hyphen "test". What is the cleanest way of doing this in bash? Note, the string could have more or less hyphens than the example.

EDIT: As a user suggested this has already been answered elsewhere and I managed to use the following to solve it:

${my_variable##*-}
Andy Cribbens
  • 1,370
  • 2
  • 11
  • 22
  • 1
    On SO we encourage users to add their efforts which they have put in order to solve their own problem, kindly add the same in your post and let us know then. Also SO's search functionality is very nice, this question is very basic you could easily get answer for this kind of question. Looking forward to you with an edited post with more efforts details etc. – RavinderSingh13 Oct 30 '19 at 15:51
  • I would say using parameter substitution, so no need to external tools. – Poshi Oct 30 '19 at 15:53
  • 1
    @RavinderSingh13 thanks for your comment. I have updated the question with the answer! – Andy Cribbens Oct 30 '19 at 15:57

0 Answers0