{{tag>Script Bash}} # Notes script bash Voir * https://linux.goffinet.org/administration/scripts-shell/ * http://pteu.fr/doku.php?id=informatique:linux:programmation_shell * http://aral.iut-rodez.fr/fr/sanchis/enseignement/IntroProgBash_2022-06-03.pdf * https://www.mode83.net/atelier/centre_ressources/crs_fichiers/Formation/OSR2K9/Linux/Programmation%20Bash.pdf * https://dev.to/rpalo/bash-brackets-quick-reference-4eh6 Voir aussi : * tinyramfs (implémentation initramfs écrite en shell POSIX ## Variables ### Fichier dans une variable - variable heredoc ~~~bash ETCHOSTS=$(cat << 'EOF' 10.245.97.221 node1 10.245.102.221 node1b EOF ) ~~~ ## Les boucles Voir aussi : * [[Notes parallel multithread multicore process shell|Les commandes Xargs et Find]] qui peuvent être des alternatives aux boucles ### For ~~~bash for (( i=1; $i<=10; i=i+1 )) do echo $i done ~~~ Voir exemple avec `seq` ci-dessous ### seq ~~~bash #for i in $(seq 10) for i in $(seq 1 10) do echo $i done ~~~ ~~~bash for i in {1..5} do echo $i done ~~~ ~~~bash seq -f "%f" 3 0.8. 6 ~~~ ~~~bash seq -f "%g/04/2018" 10 ~~~ ~~~bash seq -s - 8 ~~~ ### pb curl break `fic.lst` ~~~ foo bar ~~~ `plop_sleep.sh` ~~~bash #! /bin/bash while read -r var do echo $var timeout 1 sleep inf done < fic.lst ~~~ `plop_curl.sh` ~~~bash #! /bin/bash while read -r var do echo $var timeout 1 curl -s telnet://localhost:22 done < fic.lst ~~~ ~~~ $ ./plop_sleep.sh foo bar $ ./plop_curl.sh foo ~~~ Contournement `plop_curl_2.sh` ~~~bash #! /bin/bash while read -r var do echo $var echo timeout 1 curl -s telnet://localhost:22 | bash -s -- done < fic.lst ~~~ Vraie solution `plop_curl_2.sh` ~~~bash #! /bin/bash while read -r var do echo $var timeout 1 curl -s telnet://localhost:22