Several comments:
- See this answer to know when and how to protect your variables ;
-gt
isn't the desired operator for getting the min
Here's a simple corrected example (just Bash without other commands) :
#!/bin/bash
array=("1" "0" "2")
length="${#array[@]}"
min="${array[0]}"
for (( i=1 ; i < "$length"; i++)); do
[[ ${array[$i]} -le $min ]] && min="${array[$i]}"
done
echo "The minimum number is $min"
EDIT : Test performed after the comment of gniourf_gniourf (see the comments)
[ ~]$ cat test.sh
#!/bin/bash
array=("1" "0" "2")
m=${array[0]}; for i in "${array[@]:1}"; do ((i<m)) && m=$i; done
echo "The minimum number is $m"
[ ~]$ ./test.sh
The minimum number is 0
[ ~]$ vi test.sh
[ ~]$ cat test.sh
#!/bin/bash
array=("1" "0" "2")
m="${array[0]}"; for i in "${array[@]:1}"; do [[ $i -le $m ]] && m="$i"; done
echo "The minimum number is $m"
[ ~]$ ./test.sh
The minimum number is 0
[ ~]$