for loop with internal unix command in statement throwing error

Hi

I've gotten a plugin script that won't run. I keeps throwing an error at the following line.

for BARCODE_LINE in `cat ${TSP_FILEPATH_BARCODE_TXT} | grep "^barcode"`
do
#something
done

The error reads

/results/analysis/output/Home/Auto_KNO-12-Cardiac-panel_27_045/plugin_out/trial_out/ion_plugin_trial_launch.sh: line 146: syntax error near unexpected token `do
'
/results/analysis/output/Home/Auto_KNO-12-Cardiac-panel_27_045/plugin_out/trial_out/ion_plugin_trial_launch.sh: line 146: ` do
'

How can I get this for loop to ignore the backtick? (I tried using a semi-colon at the end of the statement)

Thanks

Can you change it to:

cat ${TSP_FILEPATH_BARCODE_TXT} | grep "^barcode" | while read BARCODE_LINE
do 
    etc...
done

(no backtick... to see if they are in cause...)

1 Like

I can reproduce the error in Post #1 by converting the script posted to MSDOS text file format, then executing it.
Was the the script created with a Microsoft Windows editor such as Notepad?

If so, it can be fixed by removing the carriage return characters:

cat scriptname | tr -d '\r' > newscriptname
1 Like

Yeah, that was my problem. I did a dos2unix and that fixed it right up.