Add_custom_target with shell looping construct

Let’s say I have a file that gets created during the build time and then I want to process that file somehow, In this example, I would like to read the file line by line and hence I try to do the following

    COMMAND while read -r line ; do echo "$line" ; done < ${CMAKE_CURRENT_BINARY_DIR}/temp.txt

however I get the following error:

/bin/sh: 1: Syntax error: end of file unexpected (expecting "do")

Please suggest how to fix this.

Thank you!!!