2

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");
}
muru
  • 193,181
  • 53
  • 473
  • 722
Alchemist
  • 193
  • 1
  • 7

1 Answers1

4

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.

muru
  • 193,181
  • 53
  • 473
  • 722
  • 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 '16 at 06:45
  • 2
    In general, run `type ` to see what exactly you're running. That should help you catch discrepancies sooner. – muru Feb 26 '16 at 06:47