http://www.politiker-stopp.de/gfx/politiker-stopp-print.png
Stoppt die Vorratsdatenspeicherung! Jetzt klicken &handeln! Willst du auch an der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:

[] breaking out of if-blocks in bash RSS feed for section Tech

Today I wanted to break out of an if-block in .

Neither the break nor the continue works mean anything in an if-block, so what to do? Create a subprocess (if your code allows it):

if [ -n "${PS1}" ] ; then
(
[ -w / ] && exit
...
)
fi



EOF

Back home  clock 20:28:38 11.03.2011 | Permalink | Trackback URI

mirabilos (2011-03-14 13:03:45)

bar=0
if foo; then
bar=1
if baz; then “break”; fi
blah=1
fi
echo $bar

This will break:

bar=0
if foo; then (
bar=1
if baz; then exit; fi
blah=1
); fi
echo $bar

This will work:

bar=0
while foo; then
bar=1
if baz; then break; fi
blah=1
break
fi
echo $bar

//mirabilos • tg@d.o • mksh author

mirabilos (2011-03-14 13:05:22)

Erm… yes.


Warning: preg_match() [function.preg-match]: Unknown modifier 'h' in /home/www/blog.crash-override.net/engine/functions.php on line 439

Your comment has been submitted

blindcoder (2011-03-14 13:18:40)

Thanks for the code example, I guess I'll use that one from now on.
The php error comes from a stray entry in my link-blacklist. Have to check where that one came from...

Leave a comment

Allowed HTML tags: a abbr acronym b blockquote em li ol p strong sub sup u ul

Name


Link (enter mailto:you@address.com for mailaddress, otherwise http:// is implied)


Comment