[BASH] - Problème d'espace dans un printf
Bien le bonjour à vous.
J'ai aujourd'hui un petit soucis d'espace en trop dans un de mes scripts de démarrage.
Pour faire simple, j'essaye d’écrire une phrase de longueur x à laquelle j'ajoute un espace (des décalages) de y puis la note [OK] ou [NOK]
Mon script fait bien ce que je lui demande, à une exception prêt, il m'ajoute un espace non désiré.
Donc, voici ce que je veux:
http://commondatastorage.googleapis....ta/OK_COLS.png
Et voici ce que j'obtiens:
http://commondatastorage.googleapis....a/NOK_COLS.png
Je met mon script ici:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: apache
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network $time
# Should-Stop: $network $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the Apache HTTP server daemon
# Description: Controls the Apache HTTP server daemon "httpd"
### END INIT INFO
### PRIMARY VARS
NB_COL=$(tput cols)
BINARY_NAME='httpd'
BINARY_PATH="/usr/local/apache2/usr/bin/$BINARY_NAME"
CONF_FILE='/etc/apache2/httpd.conf'
### SENTENCES VARS
BINARY_FOUND="Le binaire apache $BINARY_NAME a été trouvé."
BINARY_NOT_FOUND="Le binaire apache $BINARY_NAME n'a pas été trouvé."
CONF_FILE_FOUND="Le fichier de configuration apache a été trouvé."
CONF_FILE_NOT_FOUND="Le fichier de configuration apache n'a pas été trouvé."
### WIDTH CALC
WIDTH_BINARY_FOUND=$(($NB_COL - ${#BINARY_FOUND}))
WIDTH_BINARY_NOT_FOUND=$(($NB_COL - ${#BINARY_NOT_FOUND}))
WIDTH_CONF_FILE_FOUND=$(($NB_COL - ${#CONF_FILE_FOUND}))
WIDTH_CONF_FILE_NOT_FOUND=$(($NB_COL - ${#CONF_FILE_NOT_FOUND}))
if test -d "$BINARY_PATH"; then
printf "$BINARY_FOUND %*s\n" $WIDTH_BINARY_FOUND "[OK]"
exit 0
else
printf "$BINARY_NOT_FOUND %*s\n" $WIDTH_BINARY_NOT_FOUND "[NOK]"
fi
if test -e "$CONF_FILE"; then
printf "$CONF_FILE_FOUND %*s\n" $WIDTH_CONF_FILE_FOUND "[OK]"
exit 0
else
printf "$CONF_FILE_NOT_FOUND %*s\n" $WIDTH_CONF_FILE_NOT_FOUND "[NOK]"
fi
### ARGS CONTROLS |
Faites pas gaffe aux variables inutiles, ce script est en cours de test, je ferais le ménage après.
Pour obtenir le premier résultat, je suis obligé de rajouter un -1 aux opérations de calcul de la longueur, perso ça me dérange pas plus que ça, mais tant qu'à faire j'aimerais avoir un truc clean.
Merci de votre aide par avance.