2

I'm looking at this short example, and I don't see how this function works:

function EXT_COLOR () { echo -ne "\[\033[38;5;$1m\]"; }

AFAIK -ne stands for not equal. What are we comparing here? I only see one variable (string): "\[\033[38;5;$1m\]". It looks like it echoes the result of comparison, but there is no variable it compares to.

1
  • Nope, nothing to do with programming.
    – bahamat
    Sep 20, 2011 at 19:22

1 Answer 1

6

-ne only means "not equal" when it's in an if [ … ] statement. In this case -ne is an option to echo. You could just as easily use -en.

From bash(1):

If -n is specified, the trailing newline is suppressed. If the -e option is given, interpretation of the following backslash-escaped characters is enabled.

In this example there is no comparison. Just echo.

1
  • 2
    Possibly more clearly, you could also just as easily use "-n -e" -- it's two options, echo just supports merging them together under a single dash because it's unambiguous Sep 20, 2011 at 21:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .