Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


bash loop help
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

bash loop help

exussumexussum Member
edited August 2012 in General

Im Trying to loop though a file line by line and run some commands based on input.
Where im struggling is

while read line;do
echo $line;
done < item.txt

misses the first line each time. Is there something wrong with the command ?

Comments

  • AsadAsad Member
    edited August 2012

    @exussum That works fine for me and reads the first line.

    That's exactly how it's supposed to be too.

    while read LINE ; do
    echo $LINE
    done < my.file

  • exussum@exussumuk:~$ cat item.txt
    13358
    13359exussum@exussumuk:~$ bash test.sh
    13358
    

    is what i get. cat shows item.txt having 2 lines

    looking at it now, it seems the item.txt is broken.

  • AsadAsad Member
    edited August 2012

    @exussum Try this..

    for LINE in $(cat item.txt) ; do
    echo $LINE
    done

  • something like this should work as well...

    cat item.txt | while read LINE; do
    echo $LINE
    done < my.file

Sign In or Register to comment.