break
verb
say it: “BRAYK” /ˈbreɪk/
A command that stops a loop at once, so the script goes on with whatever comes after the loop.
What does break do in bash?
break leaves the loop it's in straight away, skipping every item still to come; the script carries on after done. Use it when the job is finished early, such as when the songs picked already fill the drive.
total=0
while read -r minutes title; do
[[ $(( total + minutes )) -gt 20 ]] && break
total=$(( total + minutes ))
echo "$title"
done < playlist.txt
In a sentence
- “The menu ran once, because break came straight after the choice.”
- “When the next song wouldn't fit, break ended the loop.”
Level: Apprentice · More Unix terms at this level
Updated