Results 1 to 3 of 3
I am doing a for loop in a bash script that automates compilation for a few packages. But I do not know how to make bash stop its loop when ...
- 11-10-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 7
stopping on error in a bash loop
I am doing a for loop in a bash script that automates compilation for a few packages. But I do not know how to make bash stop its loop when an error is spawned.
How to do that in a bash's for loop ?
- 11-10-2007 #2Hope this helps.Code:
#!/bin/bash for ((jndex=0;jndex<10;jndex++)) do date sleep 1 # Simulate an error after a few times through the loop. if [[ $jndex -ge 4 ]] then asdf fi # Here we check for error and exit the loop. if [ $? -ne 0 ] then break fi done--
Bill
Old age and treachery will overcome youth and skill.
- 11-10-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 7
this works perflectly, thnx


Reply With Quote