Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 24/10/2018, à 17:08

Kristobal

[Résolu] Script et galère

Salut,
J'ai un problème avec un script bash, dont la syntaxe est à priori incorrecte. Etant encore débutant en bash, je fais appel à vous pour obtenir des réponses à mon problème, et apprendre de mes erreurs.
Bon, le problème étant le suivant :

install_pf() { # {{{

echo -n "Is your computer from skylake or silvermont generation ? If not then choose generic (skylake/silvermont/generic): "
read answer
if [ "$answer" = 'skylake' ]
then
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-skylake-headers-4.19.1-1-x86_64.pkg.tar.xz
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-skylake-4.19.1-1-x86_64.pkg.tar.xz

else

if [ "$answer" = 'silvermont' ]
then
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-headers-silvermont-4.19.1-1-x86_64.pkg.tar.xz
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-silvermont-4.19.1-1-x86_64.pkg.tar.xz
   
else

if [ "$answer" = 'generic' ]
then
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-headers-generic-4.19.1-1-x86_64.pkg.tar.xz
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-generic-4.19.1-1-x86_64.pkg.tar.xz

pacman -U *pkg.tar.gz
grub-mkconfig -o /boot/grub/grub.cfg

echo "Kernel succesfully installed"

enter_to_continue 

}
# }}}

Merci d'avance.

Dernière modification par Kristobal (Le 24/10/2018, à 17:47)

Hors ligne

#2 Le 24/10/2018, à 17:14

Nuliel

Re : [Résolu] Script et galère

Bonjour,

Il manque les fi (if then else fi)
Sinon il existe elif en bash, ce serait plus propre et ça éviterait d'avoir 3 fi

Dernière modification par Nuliel (Le 24/10/2018, à 17:14)

Hors ligne

#3 Le 24/10/2018, à 17:31

Kristobal

Re : [Résolu] Script et galère

Ça donnerait quoi au niveau de la structure ?

Dernière modification par Kristobal (Le 24/10/2018, à 17:31)

Hors ligne

#4 Le 24/10/2018, à 17:35

Nuliel

Re : [Résolu] Script et galère

En remplaçant les else fi par elif et en mettant le fi à la fin de la condition, ça donne

install_pf() { # {{{

echo -n "Is your computer from skylake or silvermont generation ? If not then choose generic (skylake/silvermont/generic): "
read answer
if [ "$answer" = 'skylake' ]
then
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-skylake-headers-4.19.1-1-x86_64.pkg.tar.xz
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-skylake-4.19.1-1-x86_64.pkg.tar.xz

elif [ "$answer" = 'silvermont' ]
then
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-headers-silvermont-4.19.1-1-x86_64.pkg.tar.xz
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-silvermont-4.19.1-1-x86_64.pkg.tar.xz

elif [ "$answer" = 'generic' ]
then
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-headers-generic-4.19.1-1-x86_64.pkg.tar.xz
wget https://download.opensuse.org/repositories/home:/post-factum:/kernels/Arch/x86_64/linux-pf-generic-4.19.1-1-x86_64.pkg.tar.xz
fi

pacman -U *pkg.tar.gz
grub-mkconfig -o /boot/grub/grub.cfg

echo "Kernel succesfully installed"

enter_to_continue 

}
# }}}

Là il n'y a plus qu'une condition et non 3 conditions imbriquées. Je sais pas si j'ai mis la fin de la condition au bon endroit

Sinon on peut remplacer cette grosse condition if par un case (voir https://doc.ubuntu-fr.org/tutoriel/scri … cture_case )

Dernière modification par Nuliel (Le 24/10/2018, à 17:39)

Hors ligne

#5 Le 24/10/2018, à 17:44

Kristobal

Re : [Résolu] Script et galère

Merci, mon script refonctionne à nouveau.

Hors ligne