]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Check if stdout is a terminal in lxc-checkconfig 993/head
authorwalkerning <foxdoraame@gmail.com>
Sat, 30 Apr 2016 17:06:29 +0000 (01:06 +0800)
committerwalkerning <foxdoraame@gmail.com>
Sun, 1 May 2016 02:05:10 +0000 (10:05 +0800)
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 835202b25901ce2ae4b103b3b8193c3a98200f62..29586f869b8a728fa9ebf3346de1eff64af96428 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