I've got an interactive script that check if configuration files exist on 2 different directories, then all configuration files are print on screen by a short name.
My problem is when you type a "wrong name" or "enter" instead of one the short name given.
How can I get create a test that will check to see if you have exactly choosen one of the configuration files given ?
lst_proto=$(cat ${rep_config}/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort)
echo "${lst_proto} "
lst_proto_old=$(cat ${rep_config}/_HISTO_FIC_CFG/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort)
if [ -z ${nb_proto_old} ];
then
echo " "
echo "--------OLD PROTOTYPE-------------"
echo " "
echo "${lst_proto_old} "
echo " "
fi
echo "Please choose your configuration file : \c"
read prototype
echo "-------------------------------------------"
echo "You have choosen : ${prototype} \n"
echo "-------------------------------------------"
echo " "
#------------------------complet name files------------------
cd ${rep_config}
nom_cfg=$(${prototype}.cfg)
if [ "#"${nom_cfg}"#" == "##" ];
then
#------------------------OLD complet name files----------------------------
rep_config="${rep_config}/_HISTO_FIC_CFG"
cd ${rep_config}
nom_cfg=$(${prototype}.cfg)
fi
How to write a test that will read and check the content of $lst_proto and $lst_proto_old and see if the choice of $prototype exist in $lst_proto or in $lst_proto_old ?
Otherwise I need the script to say that the choice selected is not valid.
$lst_proto and $lst_proto_old are list of configuration files. That means $lst_proto and $lst_proto_old may have some multiple choice.
ex :
$lst_proto =
sonic
meag
$lst_proto_old =
ninte
mario
How to write a test that could read $lst_proto and $lst_proto_old to check if $prototype exist at least on one of the variables, otherwise exit.
Thanks for your help
---------- Post updated at 05:13 AM ---------- Previous update was at 05:04 AM ----------
Hi,
as I read some other posts, it seems that a case statement usually works best to check the content of variables. Does anyone can say somethings about it ?
---------- Post updated at 06:13 AM ---------- Previous update was at 05:13 AM ----------
Hello,
I do not know if what I've done is the way that it should be done but I solved my problem.
I have replaced $lst_proto and $lst_proto_old by temporary files. Here is what I have done. It could help someone ... Do not hesitate to comment my work ...
cat ${dir_config}/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort | tee ${fic_lst_proto}
nb_proto_old=$(ls ${dir_config}/_HISTO_FIC_CFG/*.cfg | wc -l )
if [ -z ${nb_proto_old} ];
then
echo " "
echo "--------OLD PROTOTYPE-------------"
echo " "
cat ${dir_config}/_HISTO_FIC_CFG/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort | tee ${fic_lst_proto_old}
echo " "
fi
echo "Please choose your configuration file : \c"
read prototype
echo "-------------------------------------------"
echo "You have choosen : ${prototype} \n"
echo "-------------------------------------------"
echo " "
if [ `cat ${fic_lst_proto} | grep ${prototype}` ] || [ `cat ${fic_lst_proto_old} | grep ${prototype}` ]
then
else
echo "\n Error while reading configuration file!\n\n"
exit
fi
Your code could be enhanced a lot ... but we would need a bit more clue about the cfg file you have.
Could you please post the result of the following commands :
ls ${dir_config}/_HISTO_FIC_CFG/*.cfg
ls ${dir_config}/*.cfg
cat ${dir_config}/_HISTO_FIC_CFG/*.cfg
cat ${dir_config}/*.cfg
The content of the configuration files do not change much. All info needed is between #tronc_staf# and #branche#.
So far I am just trying to simplify the first part of the script and make a strong condition that send warning or exit if the configuration file select is not a the list or if you type ENTER instead of selecting a file print on screen.
Info :
I do not need
#branche#supprime# RESTART_SAT
and
NOTE : for #brancheSpecifique# I need the last part of the line
#brancheSpecifique# RESTART_SAT RESTART RESTART : I am keeping the last RESTART