Looping through the content of a file in Bash

后端 未结 13 2388
傲寒
傲寒 2020-11-21 10:08

How do I iterate through each line of a text file with Bash?

With this script:

echo \"Start!\"
for p in (peptides.txt)
do
    echo \"${p}\"
done


        
相关标签:
13条回答
  • 2020-11-21 10:50

    Use a while loop, like this:

    while IFS= read -r line; do
       echo "$line"
    done <file
    

    Notes:

    1. If you don't set the IFS properly, you will lose indentation.

    2. You should almost always use the -r option with read.

    3. Don't read lines with for

    0 讨论(0)
提交回复
热议问题