Faire des qcm simplement - retour accueil
git clone git://bebou.netlib.re/qcm
Log | Files | Refs | README |
commit b1227e30d7d8247f876704bd228efdd9adab8791 parent 90b5f57d9a562fd034da5ab432eb4e925e99f36c Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Thu, 12 Dec 2024 09:06:26 +0100 Amélioration diverses issues de shellcheck On "" tout un tas de variable (même quand c'est pas vraiment nécessaire). Utilisation de -n plutôt que ! -z. Coté simplement les commandes trap pour qu'elles soient expanded quand le signal est reçu et pas au moment où elles sont déclarées (je ne savais pas). Diffstat:
M | qcm.sh | | | 32 | ++++++++++++++++---------------- |
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/qcm.sh b/qcm.sh @@ -84,8 +84,8 @@ calcandshow() { && printf "%s\n" "une ou plusieurs options vraies" \ || printf "%s\n" "une seule option vraie" [ -n "$options" ] \ - && printf "%s" "$(echo "$options" | tr '~' '\n' | paste $tmpd/o -)" \ - || printf "options : %s" "$(< $tmpd/o paste -d '\0' -s -)" + && printf "%s" "$(echo "$options" | tr '~' '\n' | paste "$tmpd/o" -)" \ + || printf "options : %s" "$(< "$tmpd/o" paste -d '\0' -s -)" ;; esac) @@ -101,37 +101,37 @@ demander() { ( * ) possibleanswers="ABCDEFGHIJQLMNOPQRSTUVWXYZ" [ -n "$options" ] && nbq=$(( $(echo "$options" | grep -o '~' | wc -l) + 1 )) - echo "$possibleanswers" | grep -o '.' | head -n$nbq > $tmpd/o - answers=$(cat $tmpd/o | tr -d '\n') + echo "$possibleanswers" | grep -o '.' | head -n"$nbq" > "$tmpd/o" + answers=$(< "$tmpd/o" tr -d '\n') pattern="[$answers]$choix ";; esac pattern="GET /$id/$pattern" - [ -p $tmpd/notif ] || mkfifo $tmpd/notif - tail -fn0 "$logs" | stdbuf -oL grep -E "$pattern" >> $tmpd/in & # PARSAGE DE LOG + [ -p "$tmpd/notif" ] || mkfifo "$tmpd/notif" + tail -fn0 "$logs" | stdbuf -oL grep -E "$pattern" >> "$tmpd/in" & # PARSAGE DE LOG tail1pid=$! - tail -fn0 "$logs" | stdbuf -oL grep -E "$pattern" > $tmpd/notif & # PARSAGE DE LOG + tail -fn0 "$logs" | stdbuf -oL grep -E "$pattern" > "$tmpd/notif" & # PARSAGE DE LOG tail2pid=$! calcandshow "$plotcmd" "$hide" - cat $tmpd/notif | while read newanswer ;do - uniqueanswers=$(< $tmpd/in sort $uopt -k1,1) + cat "$tmpd/notif" | while read newanswer ;do + uniqueanswers=$(< "$tmpd/in" sort $uopt -k1,1) [ "$olduniqueanswers" != "$uniqueanswers" ] && calcandshow "$plotcmd" "$hide" olduniqueanswers="$uniqueanswers" done & disppid=$! read _ < /dev/tty - kill $disppid $tail1pid $tail2pid + kill "$disppid" "$tail1pid" "$tail2pid" if [ -n "$hide" ];then - uniqueanswers=$(< $tmpd/in sort $uopt -k1,1) + uniqueanswers=$(< "$tmpd/in" sort $uopt -k1,1) calcandshow "$plotcmd" read _ < /dev/tty uniqueanswers=;groupedanswers=;tot=0 fi - rm $tmpd/in + rm "$tmpd/in" } nbq=4 @@ -143,7 +143,7 @@ logs="/var/log/nginx/access.log" while getopts "hegl:u:i:" opt; do case $opt in - ( l | u | i ) [ ! -z $OPTARG ] && eval "$opt='$OPTARG'" ;; + ( l | u | i ) [ -n "$OPTARG" ] && eval "$opt='$OPTARG'" ;; ( g ) command -v gnuplot > /dev/null && plotcmd="gplot" ;; ( h ) usage; exit ;; ( e ) hide="yes";; @@ -151,7 +151,7 @@ while getopts "hegl:u:i:" opt; do esac done -tmpd=$(mktemp -d ${TMPDIR:-/tmp}/qcm.XXX) +tmpd=$(mktemp -d "${TMPDIR:-/tmp}/qcm.XXX") if [ -n "$i" ];then existingids=$(ps -A -l -f | grep "[ /]qcm " | grep -o -- '-i [^ ]\+' | @@ -172,8 +172,8 @@ alias options:=options; options() { options="$*"; } alias choix:=choix; choix() { [ "$*" = "multiple" ] && choix="+" || choix=; } alias unique:=unique; unique() { [ "$*" = "non" ] && uopt= || uopt="-u"; } -trap "rm -rf $tmpd;exit" INT TERM -trap "kill 0" EXIT +trap 'rm -rf $tmpd;exit' INT TERM +trap 'kill 0' EXIT if [ -t 0 ];then <<-. cat