有进阶封装,往下看
#!/bin/bash
curl_install(){
timeout 2 bash -c 'sleep 40'
if [ $? == 124 ];then
for (( i = 0; i < 10; i++ )); do
echo $i
if (( $i == 3)); then
return 1
fi
done
curl_install
fi
}
curl_install
while [ $? -ne 0 ];do
for (( i = 0; i < 10; i++ )); do
if (( $i == 3)); then
exit 1
fi
done
curl_install
done
封装
#!/bin/bash
erro_exit(){
curl_install $1 $2
curl_install(){
timeout 2 bash -c "$1 $2"
if [ $? == 124 ];then
for (( i = 0; i < 10; i++ )); do
echo $i
if (( $i == 3)); then
return 1
fi
done
curl_install
fi
}
while [ $? -ne 0 ];do
for (( i = 0; i < 10; i++ )); do
if (( $i == 3)); then
exit 1
fi
done
curl_install
done
}
curl_test(){
erro_exit sleep 30
}
curl_test