bash: assign grep regex results to array

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-04-05T02:12:26Z Indexed on 2010/04/05 2:23 UTC
Read the original article Hit count: 339

Filed under:
|
|

Hello everyone,

I am trying to assign a regular expression result to an array inside of a bash script but I am unsure whether that's possible, or if I'm doing it entirely wrong. The below is what I want to happen, however I know my syntax is incorrect:

indexes[4]=$(echo b5f1e7bfc2439c621353d1ce0629fb8b | grep -o '[a-f0-9]\{8\}')

such that:

index[1]=b5f1e7bf
index[2]=c2439c62
index[3]=1353d1ce
index[4]=0629fb8b

Any links, or advice, would be wonderful :)

© Stack Overflow or respective owner

Related posts about bash

Related posts about array