In sh or bash How do you load a conf file (full of variables / functions) from a different directory in your script?
That way my main script can be function free so i just have to call the functions from my cfg file.
I have this setup.
Scripts in : $HOME/scripts/shl (it's in my $PATH)
Conf files in : $HOME/scripts/cfg (also equal to $CFG_DIR variable)
I can load the conf file if i put it in the same dir as the script files with
. ./filename.cfg
but it won't work if i use the script from an other directory (through PATH)
I m using different scripts with the same functions / variables and that would be really helpful to get this working..
ConfirmOrExit()
{
while true
do
echo -n "Confirmez-vous l'extraction des donn�es depuis $PWD vers $Destination? (o/n) : "
read CONFIRM
case $CONFIRM in
o|O|oui|OUI|Oui|Y|y|YES|yes|Yes) # Choix oui
echo
echo "===================================================================="
echo " D�but de l'extraction vers $Destination"
echo "===================================================================="
echo
break
;; n|N|non|NON|Non|no|NO|No) # Choix non
echo
echo "################################"
echo "# Annulation par l'utilisateur #"
echo "################################"
echo
exit
;; *) echo "Mauvais choix : (o/n)" # Mauvaise r�ponse
esac
done
}
And in my script.sh I only have
#!/bin/sh
. ./function.cfg
MYVAR=value
ConfirmOrExit #calling function from function.cfg
command1
command2
This only works if i have both files in the same directory.
I want to put my function .cfg in "../cfg" put the script won't load it. How can i make that happen?