Skip to content
Advertisement

Bash – for i in cat?

I’m not a bash scriptor, so this is no doubt a very simple question.

I have a bash script throwing an error. It looks like this:

#!/bin/bash
for i in (cat /root/list.txt)
do
        doSomething
done

The error is on the second line, related to the curly brackets. So it seems curly brackets shouldn’t be here… in which case, what should line 2 look like?

The script is supposed to read each line out of /root/list.txt and then doSomething with this (I removed the actual command for this example.)

Thanks!

Advertisement

Answer

Probably

for i in $(cat /root/list.txt)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement