bash color that works for any shell
Hi,
I have created a .c sorce file that call with "system();" a bash script .sh In this script I have done this Code:
Code:
cecho "String" $cyan 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 How can I solve it to make colors work? Thanks |
Check, you've mentioned colore while declaring it, but color while using it, in your script.
Code:
white='\E[37;40m' Code:
# white='\E[37;40m' |
Quote:
Note: I have written "white='\E[37;40m'" but of course it's the same behaviour for other colors |
What type of script it is - bash? I have doubt about how you defined variables.
|
Quote:
|
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.
|
I used: system("./script1.sh");
I'm so forgetful, you are right, infact it works in this way: system("bash script1.sh"); thanks |
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.
--- rod. |
Actually, tput itself should be terminal aware. That's why it's often recommended over raw escape sequences.
Associative arrays are also handy in cases like this. Code:
declare -A color=( |
All times are GMT -5. The time now is 07:08 PM. |