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"); }

Replies are listed 'Best First'.
Re: setting up a csh from perl
by rir (Vicar) on Jan 30, 2009 at 14:55 UTC
    You may want to just open a pipe:
    open CSH, "| csh -f -DHOME=new -DPATH=." || die "Open failed";
    It sounds like you have the whole picture:
    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: $!"; }
    Be well,
    rir