No colors are displayed when running bash -c "ls -l"
(CentOS 7.2). I have an obscure reason to want to show the colors after all. Can I disable this... color suppression?
For anyone wondering about my obscure use case: I'm running the Parcellite clipboard manager, which supports "actions" in a context menu, and one of the actions I've defined is "Run terminal command" which opens a new terminal and runs a command stored on the clipboard. It is implemented in the following way (so that the command is allowed to contain all special characters except apostrophe):
# Parcellite recognizes %s only once; store in a variable to use twice
CMD='%s' gnome-terminal -e "$SHELL -c 'echo \\\$ \"\$CMD\"; eval \$CMD; exec $SHELL'"
# Or equivalently....
CMD='%s' gnome-terminal -e $SHELL' -c "echo \$ "$CMD"; eval $CMD; exec $SHELL"'
Because gnome-terminal
can only run a single command and doesn't understand things like &&
, I need to call bash -c
($SHELL -c
) in order to interpret the command correctly and keep the shell running afterward (and since bash doesn't directly support that I have to also sneak in exec $SHELL
at the end.)
bash -c
.bash -c "ls -l --color=tty"
works as expected. It's easy to forget thatls
doesn't really meanls
! – Qwertie Nov 09 '18 at 01:01