Howdy, Stranger!

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


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
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.