[lxc-devel] [lxc/master] Check if the stdout is a terminal in lxc-checkconfig
walkerning on Github
lxc-bot at linuxcontainers.org
Sat Apr 30 17:25:36 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 526 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160430/d4b152d1/attachment.bin>
-------------- next part --------------
From d6d87d07a0440ff71fae80d00bb69560112762df Mon Sep 17 00:00:00 2001
From: walkerning <foxdoraame at gmail.com>
Date: Sun, 1 May 2016 01:06:29 +0800
Subject: [PATCH] Let lxc-checkconfig write to non-tty stdout without color
control characters
---
src/lxc/lxc-checkconfig.in | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/lxc/lxc-checkconfig.in b/src/lxc/lxc-checkconfig.in
index 835202b..29586f8 100644
--- a/src/lxc/lxc-checkconfig.in
+++ b/src/lxc/lxc-checkconfig.in
@@ -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
More information about the lxc-devel
mailing list