I have a problem with the bash command output. I want to save the result of a command for an array and cut off the first part at [0] and seccond at [1]
result=$(findId PATTERN | tr -s " " | cut -d " " -f 1)
The output of findID:
id errorcode nameOfProgramRunned
Example:
12345 "compilation problem" fullScan.java 12346 "other problem" basicTest.java
I want to save id in array[0] and nameofProgramRunned until array[1]
The main problem is that I want to avoid executing the command twice beacause, the result may be different.
Current code:
#!/bin/sh echo 'Enter error code:' read errorLine result=$(findID PATTERN | awk '{print $1}') while read -r line do dir="/proj/jobs/"$line"/screenlog.*" if [ -e $dir ] then if grep -qi "$errorLine" $dir then echo -e "\e[101m$line:\e[49m" grep $dir -i -e "$errorLine" fi fi done <<<"$result"
I want to add nameOfProgramRunned to final grep
And I use bash
source share