Mac/Apple/OSX

Some oddities concerning the default bash installed on a typical macintosh computer (osX 10.6.8)

> bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.

echo -e weirdness

Something I came across today while testing some bash-4.2 scripts on a mac; to print some text in bold I used the ancient ansi escape sequence <ESC>[1m.

Now printing this to the screen should've been simply a question of doing a quick echo -e "\e[1m bold \e[0m " … even the installed 3.2 manpage said it would. It didn't though…

> echo -e "\e[1m bold \e[0m"
\e[1m bold \e[0m

WTH? I thought as I tried some other escapes ( \n \t \a ) and without problem the newline, the tab and the sysbeep/bell sounded.

Ok, I thought, maybe escape is disabled on some level.. but just out of curiosity, and a healthy dose of boredom, I tried to

 echo -e "So what if I \033[1m give the octal value of \e033[0m escape"
and Lo-and-Behold, it printed it proper:

So what if I give the octal value of escape

Now I started getting REALLY confused…. why block the one (\e) and not the other (\033)…

But that wasn't even the annoying bit, even though my bash refuses to acknowledge the existence of \e in a echo -e double quoted string,

It has no problem giving me my beloved \e when I use a $'string'

That's right:

echo $' why dont u \e[1m W0RK \e[0m'
gave me nice and proper

why dont u W0RK

I guess someone at apple didn't like consistency too much or something. ^^

If anyone knows which setting, flag, version or environment variable van have this effect.. And/or how to fix it, please DO let me know. :)

/rant

Krim

– Don't even get me started about printf "%(%Y-%m-%d)T" -1

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
Amer Neely, 2014/12/28 19:13

Was doing some research on OSX in general and being a bit of a geek found this post very interesting. I have a Terminal window open all the time on my iMac with a couple of different tabs active. Did some looking around and found a posting at stack overflow that might shed some light on this one: <http://stackoverflow.com/questions/17015137/osx-sed-how-to-use-the-escape-character-in-the-second-field-of-a-s-operation>

Granted it is more about sed but who knows where that might lead.

You could leave a comment if you were logged in.
  • mac.txt
  • Last modified: 2012/02/10 02:28
  • by drkrimson