Fonction findbook.
<onlyinclude>
VERSION=211019
function findbook ()
 if [ "$1" = "--v" ]; then echo "findbook version : $VERSION";return 0;fi
 if [ -z $1 ]; then
 echo " -- Suffix availables in function findbook() version $VERSION : "
 echo " <book-name>/Contenus or Contenu or Contents, "
 echo " <book-name>/Sommaire or Summary, "
 echo " Compilations/<book-name> or Collections/<book-name>. "
 fi
 echo $1 | awk -F "/" '{for (i=1;i<=NF;i++) print $i}' > bookname.txt
 cat bookname.txt | grep wikibooks > sitename.txt
 read Site < sitename.txt
 wc -l bookname.txt | cut -d" " -f1 > N.txt; read N < N.txt 
 let n=N 
 let local m=N-1
 echo $1 | cut -d '/' -f5-$m > mwbookurl.txt
 read "MWbookurl" < mwbookurl.txt
 #let n-=1 
 echo $1 | cut -d '/' -f$n > lastfield.txt
 read Lastfield < lastfield.txt
 unset Suffix
 if [ "$Lastfield" = "Contenus" ] || [ "$Lastfield" = "Contenu" ] || [ "$Lastfield" = "Contents" ] || [ "$Lastfield" = "Content" ] 
 then Suffix=contents
 fi
 if [ "$Lastfield" = "Sommaire" ] || [ "$Lastfield" = "Sommaire_du_livre" ] || [ "$Lastfield" = "Summary" ]; 
 then Suffix=summary 
 else Bookname=$Lastfield 
 fi
 if [ "$Suffix" = "contents" ] || [ "$Suffix" = "summary" ]
 then
 let local m=N-1
 echo $1 | cut -d '/' -f1-$m > bookurl.txt
 read Bookfullurl < bookurl.txt
 fi
 let n-=1; echo $1 | cut -d '/' -f$n > penultimatefield.txt
 read Penultimatefield < penultimatefield.txt 
 if [ "$Penultimatefield" = "Compilations" ] \
 || [ "$Penultimatefield" = "Collections" ] \
 || [ "$Penultimatefield" = "Wikilivres:Compilations" ] \
 || [ "$Penultimatefield" = "Wikibooks:Collections" ]
 then 
 Suffix=compiled 
 else Bookname=$Penultimatefield 
 fi
 rm bookname.txt sitename.txt lastfield.txt penultimatefield.txt N.txt
</onlyinclude>
Programme des tests de la fonction findbook.
VERSION=210514
clear
 if [ "$1" = "--v" ]; 
 then 
 echo "Command 'test_findbook.bash' is $VERSION for testing findbook function";
 echo " Options : [ --v | global | <url-book> ]"
 exit 0;
 fi
 echo -e "\033[1;33m Control findbook.sh in the local test directory \033[0m" > text-control.txt
 echo -e "\033[1;33m Please check that the comment line does not contain an command \033[0m" » text-control.txt
 grep -n -e "#T\|#O\|#P" findbook.sh » text-control.txt
 more text-control.txt
 echo; echo "Continue ? y/n"
 read -s -e -n 1 -t 60 -p "y/n ? : " Inkey;echo
 if [ "$Inkey" != 'y' ]; then echo "Inkey is not yes, or time out after 60 sec, exit from $0"; exit 0;fi
 if [ "$1" = "global" ] 
 then
 echo "Global test whis annex.lib"; echo
 source $HOME/Add_appendix/datas/installdir.var
 echo "Working environnement variables :"
 echo "---------------------------------"
 echo " Install directory : Installdir=$Installdir"
 echo " Working directory : Workdir=$Workdir"
 echo " Executables directory : Bindir=$Bindir"
 echo " Tests directory : Testsdir=$Testsdir"
 Libdir=$Installdir/lib; Sharedir=$Installdir/share
 echo " Library directory : Libdir=$Libdir"
 echo " Share directory: Sharedir=$Sharedir"
 echo "----"
 source $Libdir/annex.lib
 #else source ./findbook.sh 
 #else source ~/Add_appendix/lib/src/findbook.sh
 #else source ~/Add_appendix/lib/src/annex.lib.sh
 else source ~/Add_appendix/lib/annex.lib
 fi
 if [ -n "$1" ] && [ "$1" != "global" ]; then
 echo "Test for input "$1; 
 findbook $1; 
 echo "* Site name :"$Site;
 echo "* Bookname : "$Bookname; 
 echo "* Suffix : "$Suffix; 
 echo "* Bookname.Suffix = "$Bookname.$Suffix;
 if [ "$Suffix" = "compiled" ]
 then 
 if test -n $MWcompilurl; then
 echo "Compil mw url : "$MWcompilurl
 echo -n " Compil mw syntax = "$MWcompilurl; echo " on $Site"
 echo "Compil full url : "$Compilfullurl
 fi
 else
 if test -n $MWbookurl; then
 echo "mw book url = "$MWbookurl
 echo -n " mw book syntax = "$MWbookurl/$Bookname; echo " on $Site"
 echo "Book full url = "$Bookfullurl
 fi
 fi 
 echo "----";
 exit 0;
 else
 echo "test_findbook.bash version $VERSION"
 findbook --v
 sleep 4
 echo "----"
 echo "Tests with printables versions"
 echo "------------------------------"
 echo "1. Test for 'https://en.wikibooks.org/wiki/User:Goelette_Cardabela/Sandbox/Testbook/Contents' "
 findbook https://en.wikibooks.org/wiki/User:Goelette_Cardabela/Sandbox/Testbook/Contents
 echo "Global variables after findbook execution : " 
 echo "Site name :"$Site
 echo "Bookname : "$Bookname 
 echo "Suffix : "$Suffix 
 echo "Bookname.Suffix = "$Bookname.$Suffix
 if [ "$Suffix" = "compiled" ]
 then 
 if test -n $MWcompilurl; then
 echo "Compil mw url : "$MWcompilurl
 echo -n " Compil mw syntax = "$MWcompilurl; echo " on $Site"
 echo "Compil full url : "$Compilfullurl
 fi
 else
 if test -n $MWbookurl; then
 echo "mw book url = "$MWbookurl
 echo -n " mw book syntax = "$MWbookurl/$Bookname; echo " on $Site"
 echo "Book full url = "$Bookfullurl
 fi
 fi 
 echo " ----"; echo
 echo "2. Test for 'https://fr.wikibooks.org/wiki/Hélices_de_navires_à_déplacement/Sommaire' "
 findbook https://fr.wikibooks.org/wiki/Hélices_de_navires_à_déplacement/Sommaire
 echo "Global variables after findbook execution : " 
 echo "Site name :"$Site
 echo "Bookname : "$Bookname 
 echo "Suffix : "$Suffix 
 echo "Bookname.Suffix = "$Bookname.$Suffix
 if [ "$Suffix" = "compiled" ]
 then 
 if test -n $MWcompilurl; then
 echo "Compil mw url : "$MWcompilurl
 echo -n " Compil mw syntax = "$MWcompilurl; echo " on $Site"
 echo "Compil full url : "$Compilfullurl
 fi
 else
 if test -n $MWbookurl; then
 echo "mw book url = "$MWbookurl
 echo -n " mw book syntax = "$MWbookurl/$Bookname; echo " on $Site"
 echo "Book full url = "$Bookfullurl
 fi
 fi 
 echo " ----"; echo
 echo "3. Test for 'findbook LivreTest/Contenu' "
 findbook LivreTest/Contenu
 echo "Global variables after findbook execution : " 
 echo "Site name :"$Site
 echo "Bookname : "$Bookname 
 echo "Suffix : "$Suffix 
 echo "Bookname.Suffix = "$Bookname.$Suffix
 if [ "$Suffix" = "compiled" ]
 then 
 if test -n $MWcompilurl; then
 echo "Compil mw url : "$MWcompilurl
 echo -n " Compil mw syntax = "$MWcompilurl; echo " on $Site"
 echo "Compil full url : "$Compilfullurl
 fi
 else
 if test -n $MWbookurl; then
 echo "mw book url = "$MWbookurl
 echo -n " mw book syntax = "$MWbookurl/$Bookname; echo " on $Site"
 echo "Book full url = "$Bookfullurl
 fi
 fi 
 echo " ----"; echo
 echo "Tests with compiled versions"
 echo "----------------------------";echo
 echo "4. Test for 'findbook https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/LivreTest' "
 findbook https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/LivreTest
 echo "Global variables after findbook execution : " 
 echo "Site name :"$Site
 echo "Bookname : "$Bookname 
 echo "Suffix : "$Suffix 
 echo "Bookname.Suffix = "$Bookname.$Suffix
 if [ "$Suffix" = "compiled" ]
 then 
 if test -n $MWcompilurl; then
 echo "Compil mw url : "$MWcompilurl
 echo -n " Compil mw syntax = "$MWcompilurl; echo " on $Site"
 echo "Compil full url : "$Compilfullurl
 fi
 else
 if test -n $MWbookurl; then
 echo "mw book url = "$MWbookurl
 echo -n " mw book syntax = "$MWbookurl/$Bookname; echo " on $Site"
 echo "Book full url = "$Bookfullurl
 fi
 fi 
 echo " ----"; echo
 echo "5. Test for 'findbook https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel' "
 findbook https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel
 echo "Global variables after findbook execution : " 
 echo "Site name :"$Site
 echo "Bookname : "$Bookname 
 echo "Suffix : "$Suffix 
 echo "Bookname.Suffix = "$Bookname.$Suffix
 if [ "$Suffix" = "compiled" ]
 then 
 if test -n $MWcompilurl; then
 echo "Compil mw url : "$MWcompilurl
 echo -n " Compil mw syntax = "$MWcompilurl; echo " on $Site"
 echo "Compil full url : "$Compilfullurl
 fi
 else
 if test -n $MWbookurl; then
 echo "mw book url = "$MWbookurl
 echo -n " mw book syntax = "$MWbookurl/$Bookname; echo " on $Site"
 echo "Book full url = "$Bookfullurl
 fi
 fi 
 echo " ----"; echo
 echo "6. Test for 'https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix' "
 findbook https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix
 echo "Global variables after findbook execution : " 
 echo "Site name :"$Site
 echo "Bookname : "$Bookname 
 echo "Suffix : "$Suffix 
 echo "Bookname.Suffix = "$Bookname.$Suffix
 if [ "$Suffix" = "compiled" ]
 then 
 if test -n $MWcompilurl; then
 echo "Compil mw url : "$MWcompilurl
 echo -n " Compil mw syntax = "$MWcompilurl; echo " on $Site"
 echo "Compil full url : "$Compilfullurl
 fi
 else
 if test -n $MWbookurl; then
 echo "mw book url = "$MWbookurl
 echo -n " mw book syntax = "$MWbookurl/$Bookname; echo " on $Site"
 echo "Book full url = "$Bookfullurl
 fi
 fi 
 echo " ----"; echo
 fi
 if [ "$1" = "global" ]; then
 echo; echo " ************************************************************"
 echo " * If errors are found with the global option : *" 
 echo " * find the address of the library and update it. *"
 echo " * Si des erreurs sont trouvées avec l'option globale : *"
 echo " * repérer l'adresse de la librairie et la mettre à jour. *"
 echo " ************************************************************"
 echo " Libdir is $Libdir";
 fi
 echo; echo " syntax : ./test_findbook.bash [ --v | global | <book-url> ] "
 echo " global with 'source annex.lib', else with 'source ./findbook' "