If you only need the first element (or rather the line), you can use head :
`find /xyz/abc/music/ |grep def | head -n 1`
If you need access to arbitrary elements, you can first save the array and then extract the element:
arr=(`find /xyz/abc/music/ |grep def`) echo ${arr[n]}
but this will not cause each line of the grep output file to be split into a separate array element.
If you need whole lines instead of words, you can use head and tail for this task, for example:
`find /xyz/abc/music/ |grep def | head -n line_number | tail -n 1`
MichaΕ Trybus
source share