I have this:
ql_gray='\033[1;30m'
ql_magenta='\033[1;35m'
ql_cyan='\033[1;36m'
ql_orange='\033[1;33m'
ql_green='\033[1;32m'
ql_no_color='\033[0m'
I use them like so:
echo "${ql_magenta}quicklock: could not acquire lock with name '${qln}'${ql_no_color}."
but I get this:
\033[1;35mquicklock: could not acquire lock with name '/Users/me/.quicklock/locks/_oresoftware.lock'\033[0m.
is there some flag I need to set in order to get control chars to be recognized?
Is there some flag I can check to see if the end user has allowed control chars to be recognized? If they aren't recognized, then I can just set the above to:
ql_gray=''
ql_magenta=''
ql_cyan=''
ql_orange=''
ql_green=''
ql_no_color=''
I need to support Bash versions 3+.
printf
instead ofecho
. See Why is printf better than echo? – Wildcard Mar 02 '18 at 04:00echo -e
with the -e flag might do it – Alexander Mills Mar 02 '18 at 04:01printf
is 4.1.x – Alexander Mills Mar 02 '18 at 04:03printf
is certainly in bash 3.2. – Olorin Mar 02 '18 at 04:06printf
is specified by POSIX. That's the point. It essentially doesn't matter what version you use. – Wildcard Mar 02 '18 at 04:07printf
and its standard format specifiers aren't bash specific, but bash has some extras like%b
,%q
and the-v
option, which might not be in dash'sprintf
, for example. – Olorin Mar 02 '18 at 04:10