samsheeler has asked for the wisdom of the Perl Monks concerning the following question:
I would like to set everything for a csh without the ~/.cshrc, BUT provide the effects of a ~/.cshrc without touching it.
So whereas /bin/csh -f will do that, I have no custom settings. Now I can set environment variables $ENV{var} and spawn using exec, but that leaves shell variables and aliases out. So it seems that the trick is to fork() and create a csh child and write to the stdin of the child csh.
Here is the point where I am stopped. Any ideas?
-----------------------
Well the feedback I got wasn't what I needed. Env variables are easy. I want to circumvent the .cshrc, so I'm trying something like this (close but no cigar):
pipe(STDOUT,STDIN);
unless($pid=fork()) {
defined($pid) or die "Cannot fork\n";
sleep 1; # wait for the csh to get established
print STDIN "alias myalias poopoo\n";
# reopen
open(STDIN,"</dev/tty");
open(STDOUT,">/dev/tty");
exit;
} else {
exec("/bin/csh -f -i");
}
my $child = fork;
die "Fork failed" if not defined $child;
if ( $child ) {
# parent stuff
} else {
#child
%ENV = ( what => 'ever', you => 'need' );
exec( ... ) || die "exec failed: $!";
}