]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Check if stdout is a terminal in lxc-checkconfig
authorwalkerning <foxdoraame@gmail.com>
Sat, 30 Apr 2016 17:06:29 +0000 (01:06 +0800)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 17 Nov 2016 23:20:05 +0000 (18:20 -0500)
Let lxc-checkconfig write to non-tty stdout without color control
characters
Signed-off-by: walkerning <foxdoraame@gmail.com>
src/lxc/lxc-checkconfig.in

index 4f3896e869bd740001e5d40a2d2699ad551baf6a..27689fee7af8c920af871df515c43c1165c60b6e 100644 (file)
@@ -6,10 +6,17 @@
 
 CAT="cat"
 
-SETCOLOR_SUCCESS="printf \\033[1;32m"
-SETCOLOR_FAILURE="printf \\033[1;31m"
-SETCOLOR_WARNING="printf \\033[1;33m"
-SETCOLOR_NORMAL="printf \\033[0;39m"
+if [ -t 1 ]; then
+    SETCOLOR_SUCCESS="printf \\033[1;32m"
+    SETCOLOR_FAILURE="printf \\033[1;31m"
+    SETCOLOR_WARNING="printf \\033[1;33m"
+    SETCOLOR_NORMAL="printf \\033[0;39m"
+else
+    SETCOLOR_SUCCESS=":"
+    SETCOLOR_FAILURE=":"
+    SETCOLOR_WARNING=":"
+    SETCOLOR_NORMAL=":"
+fi
 
 is_set() {
     $CAT $CONFIG | grep "$1=[y|m]" > /dev/null