|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Problem with while loop that never stops I have a shell file with me in which I have a "while" loop that never stops: I then have a file ping.txt with 4 ip in 4 lines and when I do a echo $NBS_LINE I have 4 lines Code: #!/bin/bash FILE="/home/test/ping.txt" NBS_LINE=`wc -l ping.txt | cut -d" " -f1` i=1 while [ $i=$NBS_LINE ] do HOSTNAME=`head -n $i ping.txt | tail -n 1` /bin/ping -c3 $HOSTNAME if [ $? != 1 ] then echo "$HOSTNAME;YES" else echo "$HOSTNAME;NO" fi i=$(($i + 1)) done |
#2
| |||
| |||
Re: Problem with while loop that never stops Why not you use $ i <$ NBR_LINE as a condition? Because there I even understand why your program works since $ i! = $ NBS_LINE the first execution
__________________ Grand Theft Auto 4 PC Video Game |
#3
| |||
| |||
Re: Problem with while loop that never stops If I shall be as you say it makes me: ./script_ping.sh: line 11: 4: No such file or directory type I do not know all of the report. |
#4
| |||
| |||
Re: Problem with while loop that never stops Sorry, you're absolutely right, I spoke too soon So here is the structure that I think you will need to use Code: $i = 1; while [ $i -lt $NBS_LINE ]; do Processing ... let i+=1 done
__________________ Grand Theft Auto 4 PC Video Game |
![]() |
|
Tags: shell script, while loop |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Watercooling: Single loop or Dual Loop | Akolekar | Hardware Peripherals | 3 | 21-10-2011 10:52 PM |
Game loop problem with XNA | Botan | Software Development | 5 | 30-11-2010 05:35 AM |
Problem of infinite loop in C | Firon | Software Development | 4 | 11-05-2009 06:12 PM |
Problem with a foreach loop in PHP | JiJi | Software Development | 2 | 20-11-2008 05:57 PM |
Problem - Outlook 2007 stops working under Vista | Y.A | Vista Help | 18 | 26-06-2008 06:30 AM |