0

I'm trying to grep from a file log and store it on a variable in bash. The line that I need to grep starts with *** Failure.

I've tried to store the results by doing:

response=`grep -m1 "Failure" "$LOGPATH"`

the var LOGPATH contains full file path for the log file. But when I run this command the result is: A list of all files on current dir, the line that I'm searching off example:

source3.sh source4.sh to_reproc workdir workspace.code-workspace wrkdir Failure 9134 Unmatched value in date string

to_reproc, workdir, workspace.code-workspace wrkdir are all folders, source3.sh source4.sh are shells files present in currently dir. I have a similar script doing the same thing, but instead of a fixed value it greps from a array and it works as intended. What I'm doing wrong here?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 1
    Please take a look at [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting). – Cyrus Jan 16 '23 at 20:02
  • `response=$(...whatever...)` works fine. `echo $response` does not: the `*`s are being expanded as globs because of missing quotes. Your problem is not how you _assign_ the variable; it's how you _check the value of_ the variable. (You aren't _showing us_ this code -- for how you're checking the value -- which is unfortunate, but it's a very common mistake; also, one that http://shellcheck.net/ will catch). – Charles Duffy Jan 16 '23 at 21:18

0 Answers0