Thanks for the replies. What I am trying to do is implement a limited 'which' command, one of the options being to display the alias of the input command. So the basic use of my which program would look like this:
%which -r ls
alias ='ls'
/bin/ls
I have also come across the following solution, but my experience with Linux is limited, so I am a little unsure of what it is doing:
Code:
char *buf;
buf = malloc((strlen(command)+5)*sizeof(char));
memset(buf, 0, (strlen(command)+5)*sizeof(char));
strcpy(buf, "-e ");
strcat(buf, command);
memset(buf+strlen(command)+3, '=', 1);
execl("/bin/grep", "grep", buf, STDIN_FILENO, NULL);