Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

From my most recent post: (http://stackoverflow.com/questions/15046851/linux-colorizing-text-in-files) I can now colorize text, in my terminal window. (using echo)

Now I'm to the point that I'd like to run a Shell Script that will over-write my /etc/issue whenever I decide to execute my shell script.

Here is my script:

#!/bin/sh
# re-write /etc/issue
echo "Welcome Back!........whatever message I will put later on" > /etc/issue

So now I'm looking to colorize the text "Welcome Back!"

According to This Site, I need to Escape my color codes by using Ctrl+V+ESC But how does one do that inside a shell script, with the goal to re-write the /etc/issue?

I did copy and paste the author's example (rc.issue) that he gives. Indeed, the /etc/issue file gets re-written upon boot, but no color. Just plain text shows.

Can anyone enlighten me on this?

share|improve this question

migrated from stackoverflow.com Feb 25 '13 at 14:05

This question came from our site for professional and enthusiast programmers.

    
Here's your answer. webhome.csc.uvic.ca/~sae/seng265/fall04/tips/s265s047-tips/… –  Mike Feb 24 '13 at 0:00
    
Duplicate? stackoverflow.com/questions/13054973/… –  Mike Feb 24 '13 at 0:02
add comment

1 Answer

up vote 1 down vote accepted

One way, which will work in most shells (not just bash) is to make sure the escape appears in the text of the shell script.

If you use vim, then you will still need to type Control-VEscape to enter the escape because otherwise escape changes from insert mode back to command mode.

Other editors may or may not have quirks to make this easier — or harder.

If you're using bash and don't care about portability, then there are other options available, using the \e notation for the escape (see the bash manual on ANSI-C Quoting). For example:

escape=$'\e'

This won't work with all other shells, though.

share|improve this answer
    
Yep, you're right. I do need to use the same escape method, within vim. –  coffeemonitor Feb 24 '13 at 0:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.