jeudi 24 août 2017

shell call function with command execution in conditionnal structure

I trying to run a shell app allowing me to manage a MySQL. At this point all my script do the stuff if I do not use conditionnal structure "if". My code is like this :

function selectDataBase {
  declare dbName=""

  read -p "Enter database name : " dbName

  echo "" >&2

  possibleDb=()
  loop=0

  for i in `mysql -h localhost -u root -e "show databases" | grep "$dbName"` ; do
    echo "$loop) $i" >&2
    possibleDb[$loop]=$i
    let "loop = $loop + 1"
  done

  echo "" >&2

  let "max = $loop - 1"

  selectBetween 0 $max "Select database : "
  dbNameR=$?
  dbName=${possibleDb[$dbNameR]}

  echo $dbName
}
c:\\wamp64\\wampmanager.exe &

timeout 1 sleep 10

if [[ -z $1 && -z $2 && -z $3 && -z $4 ]]; then
  flagDb=""
  while [[ $flagDb != "N" && $flagDb != "n" ]]; do
    dbName=$(selectDataBase)
  done
fi

If I remove conditionnal structure all work fine. Does any one know how to fix this?

My environment configuration is :

  • Windows 10
  • GitBash
  • GitBash is launch in administrator mode

Aucun commentaire:

Enregistrer un commentaire