Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 1 | function reorder |
| 2 | { |
| 3 | (( x[1] < x && (x=x[1], x[1]=$x) )) |
| 4 | echo "${x[@]}" |
| 5 | } |
| 6 | |
| 7 | x=(123 456) |
| 8 | reorder |
| 9 | x=(456 123) |
| 10 | reorder |
| 11 | |
| 12 | unset x |
| 13 | unset -f reorder |
| 14 | |
| 15 | function reorder |
| 16 | { |
| 17 | (( x[1] < x[0] && (x=x[1], x[1]=$x) )) |
| 18 | echo "${x[@]}" |
| 19 | } |
| 20 | |
| 21 | x=(123 456) |
| 22 | reorder |
| 23 | x=(456 123) |
| 24 | reorder |
| 25 | |
| 26 | unset x |
| 27 | unset -f reorder |
| 28 | |
| 29 | function reorder |
| 30 | { |
| 31 | (( x[1] < x[0] && (x[0]=x[1], x[1]=$x) )) |
| 32 | echo "${x[@]}" |
| 33 | } |
| 34 | |
| 35 | x=(123 456) |
| 36 | reorder |
| 37 | x=(456 123) |
| 38 | reorder |
| 39 | |
| 40 | unset -f reorder |
| 41 | |
| 42 | n=0 ; (( (a[n]=++n)<7&&a[0])); echo "${a[@]:1}" |
| 43 | |
| 44 | n=0 a="(a[n]=++n)<7&&a[0]"; ((a[0])); echo "${a[@]:1}" |
| 45 | |
| 46 | n=0 a="(a[n]=n++)<7&&a"; ((a)); echo "${a[@]:1}" |
| 47 | |
| 48 | # bugs with lvalue caching and pointer aliasing through bash-4.2 |
| 49 | echo $(( a=(y[0] + y[1]) & 0xff, b=(y[2] + y[3]) & 0xff, a << 8 | b)) |
| 50 | echo $a, $b |
| 51 | ((a = y[0], b = 1 )) |
| 52 | echo $a, $b |