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.

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

  • [email protected]:~$ cat item.txt
    13358
    [email protected]:~$ 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

    Checkout my blog. I review VPS providers and mess around with Debian and FreeBSD!

Sign In or Register to comment.