0

how to capture the jdk1.8.0_112 under /usr/jdk64

 /usr/jdk64/jdk1.8.0_112/

while jdk1.8.0_112 is example

and could be any other version as

jdk1.7.0_112
jdk3.8.2_112
jdk1.8.0_117
jdk1.2.0_112
jdk2.7.66_112
jdk1.8.2_111
jdk1.23.0_117
jdk9.2.093_112
  • 2
    Unclear: What do you mean by "capture"? Is the list that you show names of subdirectories that exists under /usr/jdk64? What is wrong with expanding the shell glob /usr/jdk64/jdk*? What are you expecting as the result (a string in a variable?) – Kusalananda May 22 at 9:49
  • 1
    What’s the higher-level problem you’re trying to solve? Why do you need this particular string, and what are you planning on doing with it? – Stephen Kitt May 22 at 10:06
  • 1
    How is this related to bash? – Inian May 22 at 10:25
1
find /usr/jdk64/* -prune -type d -name 'jdk*' | grep -P 'jdk\d+\.\d+\.\d+_\d+$'
0

One possibility for the regexp you need is:

grep -E "jdk([0-9]+).([0-9]+).([0-9_]+)"

Not the answer you're looking for? Browse other questions tagged or ask your own question.