bash ping.shを呼び出してAndroidで実行すると、このやや基本的なスクリプトで構文エラーが発生し続けます。現在、エラーは: command not found ping.sh: line 9: syntax error near unexpected token etc.
次のとおりです。私のスクリプトは次のとおりです。
#!/system/bin/sh
# check if the first argument is -all, in which case just ping all
# possible hosts
if [ $# -ge 1 ]; then
if [ $1 == "-all" ]
then
# loop through all IPs
for ((host=1; host<100; host++))
do
ping -c3 192.168.0.$host > /dev/null && echo "192.168.0.$host UP"
done
else
# loop through the hosts passed in
while test $# -gt 0 # while number of arguments is greater than 0
do
ping -c3 $1 > /dev/null && echo "$1 UP" || echo "$1 DOWN"
shift # shift to the next argument, decrement $# by 1
done
fi
else
# if the number of arguments is 0, return a message stating invalid input
echo "No arguments specified. Expected -all or host names/ip addresses."
echo "Usage: ping: -all"
echo "Or: ping: 192.168.0.1,192.168.0.16"
fi