Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I called "ls" command using the execvp system call from inside a c file. But there seems to be a slight difference.

enter image description here

The exe files in the default ls call are highlighted green But not in my own execvp ls call. Am I missing something?

This is the piece of code that is calling ls.

else if (rc == 0) 
{ 
    // child (new process)
    printf("hello, I am child (pid:%d)\n", (int) getpid());
    char *myargs[2];
    myargs[0] = strdup("ls");
    // program: "wc" (word count)
    myargs[1] = NULL;//strdup("p3.c"); // argument: file to count
    //myargs[2] = NULL;
    // marks end of array
    execvp(myargs[0], myargs); // runs word count
    printf("this shouldn’t print out");
}
share|improve this question

marked as duplicate by muru command-line Feb 27 at 16:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 4 down vote accepted

ls in your shell is an alias to ls --color=auto:

$ alias ls
alias ls='ls --color=auto'

If you want the colouring in ls output, use the --color option.

share|improve this answer
    
Thanks a lot. That was helpful. I can't accept the answer within another 8 minutes. So just a little longer :p – Alchemist Feb 26 at 6:45
2  
In general, run type <name-of-command> to see what exactly you're running. That should help you catch discrepancies sooner. – muru Feb 26 at 6:47
    
Thanks for the tip. – Alchemist Feb 26 at 6:55

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