Interactive script – if then

Hi,

I am writing an interactive shell script (ksh) but I have no idea how I could make a condition on it :

Variables :
  rep_config="${rep_tools}/_CONFIG"
  rep_config_old="${rep_config}/_PROTO_OLD"
  
  
Here is the interactice part :
  lst_proto=$(cat ${rep_config}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort)
  lst_proto_old=$(cat ${rep_config_old}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort)
   
  echo "$lst_proto : "
  echo " "
  echo "--------OLD PROTOTYPE-------------"
  echo "$lst_proto_old : \c"
   
  read prototype
  echo "-------------------------------------------"
  echo "You have Chosen : $prototype \n"
  echo "-------------------------------------------"
  echo " "
  
Here is the idea :

The CAT command goes on 2 differents directory and then find inside on all configuation files the name of the data you want to choose. There one directory for the current data and another directory for the old data.

    DIR1
  IDEFIX.cfg
  "#nom_transfert#" will return IDEFIX
   
              DIR2
              ASTERIX_old.cfg
              "#nom_transfert#" will return ASTERIX
  
My needs is to create a condition that will say something like this :

If $prototype has been chosen from $ls_proto do this ..... otherwise do this ....

I did try to make something like :

  cat ${rep_config}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort> listeprotocfg
  cat ${rep_config_old}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'|sort> listeprotocfg_old
   
   
   
  #echo "$lst_proto : "
  echo $(( cat listeprotocfg ))
  echo " "
  echo "--------OLD PROTOTYPE-------------"
  echo " "
  #echo "$lst_proto_old : \c"
  echo $(( cat listeprotocfg_old ))
  read prototype
   
  type_proto=grep ${prototype} listeprotocfg
   
  if type_proto="" then
  # If the PROTYPE IS OLD
  fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
  rep_config="${rep_config}/_PROTO_OLD"
  nom_fichier=grep $prototype $rep_config/*  | awk -F":" '{print $1}'
  else
   
  fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
   
  fi
   
  echo "-------------------------------------------"
  echo "YOU HAVE CHOSEN : $prototype \n"
  echo "-------------------------------------------"
  echo " "
  

As you can see it is not really good... I hope you will be able to help me to make it right.

Thanks

Maybe something like this (not tested, i haven't any source data)

cat listeprotocfg   # Simply !
echo   # Simply !
echo "--------OLD PROTOTYPE-------------"
echo   # Simply !
# The 3 lines above can be replaced by :
# echo -e "\n--------OLD PROTOTYPE-------------\n"
cat listeprotocfg_old
read prototype
# type_proto=grep ${prototype} listeprotocfg
# if type_proto=""
# then
if grep $prototype listeprotocfg   # Simply !
then
   fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
   rep_config="${rep_config}/_PROTO_OLD"
   nom_fichier=grep $prototype $rep_config/*  | awk -F":" '{print $1}'
else
   fic_tmp_arbo=${rep_tmp}/controleSTAF_arbo_branche.txt
fi
echo "-------------------------------------------"
echo "YOU HAVE CHOSEN : $prototype" # no '\n' needed (like in printf). For use of special characters, yoiu have to use the -e (extended) option of echo
echo "-------------------------------------------"
echo

Hi ,

here is what have done so far ... it's not working yet as i am trouble with the test argument but you maybe could help me on this ... I am not good enought to say i am doing it on the right way ....

lst_proto=$(cat ${rep_config}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'| sort)
lst_proto_old=$(cat ${rep_config_old}/*.cfg | grep "#nom_transfert#" | awk -F" " '{print $2}'| sort)

echo "$lst_proto : "
echo " "
echo "--------OLD PROTOTYPE-------------"
echo " "
echo "$lst_proto_old : \c"

read prototype

echo "-------------------------------------------"
echo "You have chosen : $prototype \n"
echo "-------------------------------------------"
echo " "

#------------------------Prototype version------------------------

type_proto=$( ls * ${rep_config} | grep ${prototype} | grep .cfg )
if [ ${type_proto} = " " ] ;
then

#------------------------Prototype OLD----------------------------
cd ${rep_config_old}
pwd
type_proto=$(ls * | grep ${prototype} | grep .cfg | head -1 )
echo ${type_proto}
tronc_staf=$(cat ${type_proto} | grep "#tronc_staf#" | awk '{print $2}' )
echo $tronc_staf
cat ${type_proto} | grep "#nbr_feuille_par_#branche#" | awk -F" " '{print $2}' > ${fic_tmp_arbo}

else

#------------------------Prototype current------------------------
cd ${rep_config}
pwd
echo ${type_proto}
tronc_staf=$(cat ${type_proto} | grep "#tronc_staf#" | awk '{print $2}' )
echo $tronc_staf
cat ${type_proto} | grep "#nbr_feuille_par_#branche#" | awk -F" " '{print $2}' > ${fic_tmp_arbo}

fi