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.

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

-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.

| improve this answer | |
  • 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 – Michael Mrozek Sep 20 '11 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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