isposix

Un outil pour savoir si une commande est posix - retour accueil

git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |

commit 01f2531df55cc1a187a93741e08310ed3f4c37f2
parent 8d24f7c709b99feb235956aa88c94e23e95a1b86
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Sun, 24 Nov 2024 22:52:02 +0100

Les options sont parsées correctement

Aussi, le script retourne 1 si au moins une des commandes ou options
n'est pas posix
Mais utiliser /dev/stdin pour éviter de piper dans la boucle while et
ainsi créer un subshell n'ayant pas accès à $scriptisposix
Comment résoudre ça de manière plus portable ?

Diffstat:
Misposix | 35+++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/isposix b/isposix @@ -11,7 +11,7 @@ _cmdnotposix() { xargs -I{} basename {} | sed 's/\.html$//' | fzy -e "$cmd" | head -n3) fi - [ -z "$fzcmd" ] && { _die "$cmd is not posix"; return 1;} + [ -z "$fzcmd" ] && { _die "$cmd"; return 1;} if [ -t 0 ];then _inform "$cmd appears not to be posix, did you mean : $norm" cmd=$(echo "$fzcmd" | fzy) @@ -36,27 +36,30 @@ usage() { checkoption() { cmd="$1";option="$2" - < bdd/$cmd.html grep -Eq "<dt><b>-$option.*</dt>" \ + < bdd/$cmd.html grep -Eq "<dt><b>-$option[&<].*</dt>" \ && { _success " -$option";return 0;} \ || { _die " -$option"; return 1;} } -cat | while read line;do +scriptisposix=0 +while read line;do set -- $line - isposix=0 + cmdisposix=0 cmd="$1";shift - [ ! -f bdd/$cmd.html ] \ - && { _cmdnotposix;isposix=1; } \ - || _success "$cmd" - while getopts "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" opt; do - case "$opt" in - ( * ) checkoption "$cmd" "$opt" || isposix=1;; - esac - done - [ $isposix = "0" ] \ + if [ ! -f bdd/$cmd.html ];then + _cmdnotposix || cmdisposix=1 + else + _success "$cmd" + while getopts "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" opt; do + case "$opt" in + ( * ) checkoption "$cmd" "$opt" || cmdisposix=1;; + esac + done + fi + [ $cmdisposix = "0" ] \ && _success " : is posix\n" \ - || _die " : not posix\n" -done + || { _die " : not posix\n";scriptisposix=1; } +done < /dev/stdin -exit $isposix +exit $scriptisposix