Rev | Line | |
---|
[2] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | #-----[ usage ]--------------------------------------------- |
---|
| 4 | function usage () |
---|
| 5 | { |
---|
| 6 | echo "Usage : $0 min max [step [iter]]"; |
---|
| 7 | echo " * min : value minimal"; |
---|
| 8 | echo " * max : value maximal"; |
---|
| 9 | echo " * step : step between two value. If no present, step = \"+1\""; |
---|
| 10 | echo " * iter : choose the Nième value"; |
---|
| 11 | exit; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | #-----[ range ]--------------------------------------------- |
---|
| 15 | function range () |
---|
| 16 | { |
---|
| 17 | declare a=$1; |
---|
| 18 | declare b=$2; |
---|
| 19 | declare step=$3; |
---|
| 20 | |
---|
| 21 | while test $a -le $b; do |
---|
| 22 | echo $a; |
---|
| 23 | a=$(($a $step)); |
---|
| 24 | done |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | #-----[ range_max ]----------------------------------------- |
---|
| 28 | function range_max () |
---|
| 29 | { |
---|
| 30 | declare a=$1; |
---|
| 31 | declare b=$2; |
---|
| 32 | declare step=$3; |
---|
| 33 | declare iter=$4; |
---|
| 34 | |
---|
| 35 | while test $a -le $b -a $iter -gt 1; do |
---|
| 36 | a=$(($a $step)); |
---|
| 37 | iter=$(($iter-1)); |
---|
| 38 | done; |
---|
| 39 | |
---|
| 40 | if test $iter -eq 1; then |
---|
| 41 | echo $a; |
---|
| 42 | fi; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | #-----[ main ]---------------------------------------------- |
---|
| 46 | function main () |
---|
| 47 | { |
---|
| 48 | # create operande |
---|
| 49 | case $# in |
---|
| 50 | 2) range $* "+1";; |
---|
| 51 | 3) range $* ;; |
---|
| 52 | 4) range_max $* ;; |
---|
| 53 | *) usage $* |
---|
| 54 | esac |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | #-----[ Corps ]--------------------------------------------- |
---|
| 58 | main $* |
---|
Note: See
TracBrowser
for help on using the repository browser.