linux - Shell script doesn't run -


can , tell me why isn't working?

i have checked script , solved problems still doesn't works fine , can't find mistake.

#!/bin/bash  #variabelen  ip="192.168.0." array=($@)  #functies 

what's wrong array? linux told me there syntax error on line 12 array doesn't tell me what.

function sorteer(){  array=($(printf '%s\n' "$@"|sort -nu)) in ${array[@]};do ping -c -1 "ip"$i done  }  function telbij(){ # given number $i +200     b=$(( $i + 200 ))         if (( b > 255 ))             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#*-} ((i=start;i<=end;i++));do     ping -c 1 "$ip"$i done } 

the mistake in if else function: http://prntscr.com/7gr8yf

but don't know means: "the mentioned parser error in else clause."

if [ "$#" -eq 0 ];            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 not working but,

in sorteer function should double quote array expansions avoid re-splitting elements. try change following:

function sorteer(){  array=($(printf '%s\n' "$@"|sort -nu)) in "${array[@]}";do ping -c -1 "ip"$i done 

}

now case operator should 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 fix if issue well


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -