On 1/12/15 4:26 AM, l_j_f wrote: > 1. bash version > -sh-4.3# bash --version > GNU bash, version 4.3.0(1)-release (arm-hisiv200-linux-gnu) > Copyright (C) 2013 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> > This is free software; you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. > > 2. the script > #!/bin/bash > > main() { > local idx > local current=1 > > for ((idx=0; idx<3 && idx != current; idx++)); do > echo $idx > done > } > > main "$@" > > 3. the result > -sh-4.3# ./test1.sh > 0 > # I think it should be > 0 > 2
Why? The for loop breaks when the condition tests false. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/