第2题
#!/bin/sh
echo "please input a number list:"
read -a arr
for (( i=0 ; i<${#arr[@]} ; i++ ));do
for (( j=${#arr[@]}-1 ; j>i ; j-- ));do
if [[ ${arr[j]} -lt ${arr[j-1]} ]];then
t=${arr[j]}
arr[j]=${arr[j-1]}
arr[j-1]=$t
fi
done
done
echo "after sorting:"
echo ${arr[@]}
第3题
#!/bin/bash
square() {
squ=$[$1*$1]
echo $squ
}
cubic() {
cub=$[$1*$1*$1]
echo $cub
}
for i in `seq 1 10`;do
echo $i `square $i` `cubic $i`
done
echo