Bash Script Looping all the time

Hello,

I have a database file, named data.txt, and a shell script (convert.sh) to convert data.txt from columns to row. Output file name will be column_to_row.txt
In this example data.txt has only four rows.

Format of data.txt is:
info name surname telefon_nr

Data.txt

info boris vian 0012345678
info kristaq skowronska 009876567
info emmanuel kant 00987654321

convert.sh

#!/bin/bash
while read -r COL1 COL2 COL3 COL4
sleep 2
do
echo "
[info_card]
name                          = "$COL2"
surname                      = "$COL3"
phone_nr                     = "$COL4" "
done < Data.txt
exit 0

To run convert.sh, i enter below command in terminal:

./convert.sh > column_to_row.txt

When I run it, script is not ending until i press ctrl+c. After processing four lines, it keeps running. How may I stop this script when all lines existing in data.txt file are processed ?

Many Thanks
Boris

Sleep 2 always has a return code 0; therefore the loop will run indefinitely...

The sleep 2 should be after the do

1 Like