Answer the question
In order to leave comments, you need to log in
How to extract a word from a string in bash?
Good afternoon habrayudi.
Faced such a problem - it is necessary to select the first word from the end (before the slash) from the string, for example, "/etc/somewhere" into another variable.
How to implement this in bash?
Thanks in advance
Answer the question
In order to leave comments, you need to log in
If it is stored in a variable, then:
T=/etc/somewhere ; echo ${T##*/}
Try sed 's|.*/||'
Example:
[email protected]:~$ echo /etc/somewhere | sed 's|.*/||'
somewhere
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question