informatique:linux:programmation_shell
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
informatique:linux:programmation_shell [2020/01/14 14:58] – [Tableau associatif] pteu | informatique:linux:programmation_shell [2020/01/24 07:50] – [Nombres, comparaison] tester si VAR est un nombre pteu | ||
---|---|---|---|
Line 529: | Line 529: | ||
* '' | * '' | ||
+ | Comme il n'y a pas de typage en bash, pour tester si la valeur d'une variable est un nombre (entier) il faut réaliser le tester : | ||
+ | <code bash> | ||
+ | # Solution à base de REGEX | ||
+ | [[ $VAR =~ ^[0-9]+$ ]] || echo "VAR n'est pas un entier" | ||
+ | # NB : l' | ||
+ | # ou doit être enregistrée dans une variable sinon ça ne matche pas | ||
+ | |||
+ | # " | ||
+ | [ $VAR -eq $VAR ] 2>/ | ||
+ | </ | ||
==== Opérateurs ==== | ==== Opérateurs ==== | ||
* '' | * '' |
informatique/linux/programmation_shell.txt · Last modified: 2023/10/02 13:35 by pteu