Read file line by line with bash script

bash, command, if-statement, regex

Solution

The problem in this case is the spaces around the `=` sign in `regex = '^[0-9]+/[0-9]+/[0-9]+$'`

It should be

regex='^[0-9]+/[0-9]+/[0-9]+$'

ShellCheck automatically warns you about this, and also suggests where to quote your variables and how to read line by line (you're currently doing it word by word).

Problem

I need a bash script to read a file line by line. If a regex match, echo this line. The script is the following: ``` #!/bin/bash echo "Start!" for line in $(cat results) do regex = '^[0-9]+/[0-9]+/[0-9]+$' if [[ $line =~ $regex ]] then echo $line fi done ``` It is printing the file content, but show this warning: ``` ./script: line 7: regex: command not found ``` Where is the error?

Original source