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 [2022/06/08 08:49] – [Ressources] pteu | informatique:linux:programmation_shell [2022/10/17 21:28] – [trim] pteu | ||
---|---|---|---|
Line 944: | Line 944: | ||
</ | </ | ||
+ | =====trim (suppression des espaces dans une chaîne)===== | ||
+ | |||
+ | bash ne possède pas de fonction prédéfinie pour " | ||
+ | |||
+ | Pour faire cette office il existe plusieurs possibilités d' | ||
+ | <code bash> | ||
+ | arr=(' | ||
+ | ' test@domain.com ' ' | ||
+ | </ | ||
+ | |||
+ | * en utilisant la substitution de caractère dans les variables, en activant le //globbing étendu// (des motifs d' | ||
+ | <code bash> | ||
+ | shopt -s extglob | ||
+ | # (pour reconnaître [[:blank:]] qui définit l' | ||
+ | arr=( " | ||
+ | arr=( " | ||
+ | </ | ||
+ | |||
+ | * avec '' | ||
+ | <code bash> | ||
+ | function trim() { | ||
+ | mapfile -t t_input<<<" | ||
+ | [[ ${# | ||
+ | set -- ${t_input[@]} | ||
+ | printf ' | ||
+ | } | ||
+ | trim " | ||
+ | </ | ||
====== Ressources ====== | ====== Ressources ====== | ||
informatique/linux/programmation_shell.txt · Last modified: 2023/10/02 13:35 by pteu