##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 ## Fonctions de base: support des fonctions obsolètes et des versions de bash < 4.x ##@cooked nocomments uprovide base.compat urequire base.string if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then if uprovided base.string; then function strlower() { tr A-Z a-z <<<"$*"; } function strlower1() { local str="$*" local h="${str:0:1}" r="${str:1}" echo "$(tr A-Z a-z <<<"$h")$r" } function strlowers() { local -a vs; local v for v in "$@"; do vs=("${vs[@]}" "$(strlower1 "$v")") done echo "${vs[*]}" } function strupper() { tr a-z A-Z <<<"$*"; } function strupper1() { local str="$*" local h="${str:0:1}" r="${str:1}" echo "$(tr a-z A-Z <<<"$h")$r" } function struppers() { local -a vs; local v for v in "$@"; do vs=("${vs[@]}" "$(strupper1 "$v")") done echo "${vs[*]}" } function is_yes() { case "$1" in o|oui|y|yes|v|vrai|t|true|on) return 0;; O|OUI|Y|YES|V|VRAI|T|TRUE|ON) return 0;; esac isnum "$1" && [ "$1" -ne 0 ] && return 0 # pour les perfs, n'utiliser strlower que ici case "$(strlower "$1")" in o|oui|y|yes|v|vrai|t|true|on) return 0;; esac return 1 } function is_no() { case "$1" in n|non|no|f|faux|false|off) return 0;; N|NON|NO|F|FAUX|FALSE|OFF) return 0;; esac isnum "$1" && [ "$1" -eq 0 ] && return 0 case "$(strlower "$1")" in n|non|no|f|faux|false|off) return 0;; esac return 1 } fi fi