*BSDThis forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
and it works (it shows colors) in geany terminal emulator and also in normal gnome terminal and kde terminal (konsole).
The problem is that it doesn't work while running .c file.
I use Codeblocks to compile and run .c files and it can use "konsole", "gnome terminal" or "xterm" as terminal but it doesn't work with any of them. It calls myscript.sh and shows this:
Code:
\E[37;40m String
without colors.
How can I solve it to make colors work?
Thanks
Last edited by Hoxygen232; 01-22-2013 at 10:22 AM.
sorry I have just copied wrong in here, yes I already had color=${2:-$white} and it works only in normal terminal but it does not in .c file, that's the problem.
Note: I have written "white='\E[37;40m'" but of course it's the same behaviour for other colors
Last edited by Hoxygen232; 01-22-2013 at 08:48 AM.
What type of script it is - bash? I have doubt about how you defined variables.
it's bash, and it works in all terminals (it display different colors), but when running .c file and so it runs the script it doesn't display colors in any terminal
How do you call the script in your .c file? May it be possible that you run the script with sh instead of Bash? May be adding a proper shebang at the beginning of the script helps.
Color rendering is a function of the terminal type, not the shell. Various terminal programs such as xterm and konsole have different emulations, and so respond differently to the embedded escape sequences you're using. The easiest way to build in terminal handling like you want is to use the ncurses library, which knows all about the various terminal types and how to control them.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.