diff options
author | Mu Qiao <qiaomuf@gentoo.org> | 2011-06-20 22:48:22 +0800 |
---|---|---|
committer | Mu Qiao <qiaomuf@gentoo.org> | 2011-06-23 11:24:43 +0800 |
commit | 4a6aa796319c9dbc9ac1b50c846c6f4b009c196f (patch) | |
tree | 40d689029130421e5c5d5f817e08aa14a77ce4c2 /scripts | |
parent | Walker: fix a bug in for each loop (diff) | |
download | libbash-4a6aa796319c9dbc9ac1b50c846c6f4b009c196f.tar.gz libbash-4a6aa796319c9dbc9ac1b50c846c6f4b009c196f.tar.bz2 libbash-4a6aa796319c9dbc9ac1b50c846c6f4b009c196f.zip |
Walker: support break built-in
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/compound_command.bash | 79 | ||||
-rw-r--r-- | scripts/compound_command.bash.result | 9 |
2 files changed, 84 insertions, 4 deletions
diff --git a/scripts/compound_command.bash b/scripts/compound_command.bash index 06b4f9e..ece5504 100644 --- a/scripts/compound_command.bash +++ b/scripts/compound_command.bash @@ -46,6 +46,22 @@ do echo $file done +for file in foo bar +do + if [[ $file == "foo" ]]; then + break + fi + echo $file +done + +for file in foo bar +do + if [[ $file == "bar" ]]; then + break + fi + echo $file +done + for outer in 1 2 3 do for file in foo bar @@ -57,6 +73,17 @@ do done done +for outer in 1 2 3 +do + for file in foo bar + do + if [[ $file == "foo" && $outer == 1 ]]; then + break 2 + fi + echo "$outer $file" + done +done + i=0; while [ $i != 4 ] do @@ -80,6 +107,16 @@ do done i=0 +while [ $i != 4 ] +do + i=$(( i + 1 )) + if [[ $i == 1 ]]; then + break + fi + echo $i +done + +i=0 j=1 while [ $i != 4 ] do @@ -95,6 +132,22 @@ do done done +i=0 +j=1 +while [ $i != 4 ] +do + i=$(( i + 1 )) + + while [ $j == 1 ] + do + if [[ $i == 1 ]]; then + break 2 + fi + echo $i + let ++j + done +done + i=0; until [ $i == 4 ] do @@ -118,6 +171,16 @@ do done i=0 +until [ $i == 4 ] +do + i=$(( i + 1 )) + if [[ $i == 1 ]]; then + break + fi + echo $i +done + +i=0 j=1 until [ $i == 4 ] do @@ -133,6 +196,22 @@ do done done +i=0 +j=1 +until [ $i == 4 ] +do + i=$(( i + 1 )) + + while [ $j == 1 ] + do + if [[ $i == 1 ]]; then + break 2 + fi + echo $i + let ++j + done +done + a=1 b=2 if [ $a == $b ] diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result index 4662025..c083e6a 100644 --- a/scripts/compound_command.bash.result +++ b/scripts/compound_command.bash.result @@ -13,6 +13,7 @@ ghi 10 bar foo +foo 2 foo 2 bar 3 foo @@ -52,9 +53,9 @@ case end a=1 b=2 bar= -file=bar +file=foo foo=ghi -i=4 -j=2 -outer=3 +i=1 +j=1 +outer=1 target=_ |