vendredi 24 septembre 2021

If ... Else ... If.... Bash

Good Morning!

I have (3) scenarios going with inputs and I cant wrap my head around on how to solve this.

  • host=$1 (name)
  • info=$2 (info)
  • type=$3 (a, b)

name >> info > code will update with new supplied info

name >> info >> type > code will update with new supplied info by type

name >> type > the prompt type will update the info

Im trying to figure out how I can skip over the 2nd input in one of the scenarios above.

Any help is appreciated. Thanks!

if [ "$type" == "a" ]; then
  if [ $# -ne 2 ]; then
      usage1
  fi

elif [ "$type" == "b" ]; then
  if [ $# -ne 3 ]; then
      usage2
  fi

else
    if [ $# -ne 2 ]; then
       usage
    fi
fi


if [ "$type" == "a" ]; then
  ...command
  ...command

elif [ "$type" == "b" ]; then
  ...command
  ...command

else
  ...command
  ...command
fi

Aucun commentaire:

Enregistrer un commentaire