How to use the exec function to start a connection shell (csh)?

advertisements

I have already known that I can use the parameter -l to start a bash or ksh as a login shell, so I don't have to source the files like ~/.profile,~/.bash_profile and so on. But in csh,the sentence

execl("/bin/csh","csh","-l","-c","env",NULL);

is wrong, the wrong information is

Unknown option: `-l'

but I looked up the csh man page and find that -l means

"The shell is a login shell. Applicable only if -l is the only flag specified.".

So I changed the sentence to

execl("/bin/csh","csh","-l",NULL);

and

execl("/bin/csh","csh","-c","env",NULL);

but when I run the program, it suspended there. Could you please tell me how to solve it?


Try to run it this way instead:

execl("/bin/sh","sh","-l","-c","exec csh -l",NULL);

By the way, how did you know that -l for other shells was the solution? ;)