Can someone help and tell me why this isn't working?
I have checked the script and solved some problems but it still doesn't works fine and I can't find the mistake.
#!/bin/bash
#variabelen
IP="192.168.0."
array=($@)
#functies
What's wrong with the array? My linux told me that there is a syntax error on line 12 so with that array but he doesn't tell me what.
function Sorteer(){
array=($(printf '%s\n' "$@"|sort -nu))
for i in ${array[@]};do
ping -c -1 "IP"$i
done
}
function Telbij(){
# given number $i +200
b=$(( $i + 200 ))
if (( b > 255 ))
then
echo "Neem kleiner getal";
else
ping -c 1 "IP"$b;
fi
}
function XXYY() {
#ping 65-68 = ping 65 66 67 68
start=${1%-*}
end=${1#*-}
for ((i=start;i<=end;i++));do
ping -c 1 "$IP"$i
done
}
The mistake is in the if else function: http://prntscr.com/7gr8yf
But I don't know what that means: "The mentioned parser error was in this else clause."
if [ "$#" -eq 0 ]; then
echo "Er moet minimaal 1 parameter worden meegegeven "
exit 0
else
case
-h -help ) echo "Geef de laatste cijfers van het IP-adres van de pc's om te testen.";;
XX-YY ) XXYY;;
-t ) Telbij;;
- sort ) Sorteer;;
esac
fi
done
Don't know what's specifically not working but,
in Sorteer
function you should double quote array expansions to avoid re-splitting elements. Try change to following:
function Sorteer(){
array=($(printf '%s\n' "$@"|sort -nu))
for i in "${array[@]}";do
ping -c -1 "IP"$i
done
}
Now your case
operator should be like:
case $some_value in
-help ) echo "Geef de laatste cijfers van het IP-adres van de pc's om te testen.";;
XX-YY ) XXYY;;
-t ) Telbij;;
-sort ) Sorteer;;
esac
This will fix your if
issue as well
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.