title: How can I get csh to source a file and then go interactive?
body: <h1>BRIEF</h1>
  
  <p>how do I (1) start a new csh, (2) force it to execute a few commands that are NOT in any .cshrc (although I could arrange for them to be in a non-standard location to be source'ed) and (3) then go interactive?</p>
  
  <p>E.g. is there any way to get csh or tcsh to sue alternate startup files other than those described at <a href="http://www.manpagez.com/man/1/tcsh/" rel="noreferrer">http://www.manpagez.com/man/1/tcsh/</a>, which says</p>
  
  <h2>I already know about</h2>
  
  <p>Startup and shutdown
         A  login  shell  begins  by  executing  commands  from the system files
         /etc/csh.cshrc and /etc/csh.login.   It  then  executes  commands  from
         files  in  the  user's  home  directory:  first  ~/.tcshrc  (+)  or, if
         ~/.tcshrc is not found, ~/.cshrc, then ~/.history (or the value of  the
         histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the
         value of  the  dirsfile  shell  variable)  (+).   The  shell  may  read
         /etc/csh.login  before  instead  of  after /etc/csh.cshrc, and ~/.login
         before instead of after ~/.tcshrc or ~/.cshrc  and  ~/.history,  if  so
         compiled; see the version shell variable. (+)</p>
  
  <pre><code>   Non-login  shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc
  </code></pre>
  
  <h1>DETAIL</h1>
  
  <p>I'm a bash user.  But I work at a hardware company, where (1) many people are csh users, and (2) many of the CAD tools depend on stuff in the environment, such as the modules system.</p>
  
  <p>Many recipes - e.g. internal wiki pages where people explain how to do things - start off something like</p>
  
  <pre><code>start a new shell or xterm
  source /proj/Foo/setup.proj
  source ~some_engineer/env/setup-for-this-tool
  now run the tool
  </code></pre>
  
  <p>Oftentimes the environment variables conflict; sometimes I have to delete all of my ~/.* files, ssh in afresh, etc.</p>
  
  <p>I would like to automate many of these.  Indeed, I have automated many of these.  However, I had to automate them by using expect (actually, Perl CPAN Expect), to fake out being an interactive user.</p>
  
  <p>Along the way, I have my own script clear-env that I often use to start a shell with almost no environment variables. Used thusly:</p>
  
  <pre><code>clear-env -keep HOME -- csh
  and then either pipe commands in through expect
  or run interactively
  </code></pre>
  
  <p>This works for automation.  But sometimes I really do need to be interactive - but only after I have loaded several lines of long source script names.</p>
  
  <p>I would like to be able to load thes source files, and then fall back to interactive.</p>
  
  <p>E.g. I have tried</p>
  
  <pre><code>clear-env -keep HOME -- csh -c 'source filename' -i
  ...
  </code></pre>
  
  <p>or, without my clear-env</p>
  
  <pre><code>csh -c 'source filename' -i
  ...
  </code></pre>
  
  <p>hoping that it would execute the -c command and then become interactive.  But it only executes the -c command.</p>
  
  <p>I have been able to feed commands to csh via expect in a perl script of my own, that reads my tty, and then pipes the command into the csh via expect.  However, then I lose the interactive features of csh.</p>
  
  <p>Is there any better way?  Some way of saying "From this point on, I want you to reconnect youir controlling terminal to this other terminal?"</p>
  
  <p>Thanks.</p>
  
  <p>By the way, this would be useful for other shells as well. However, it has been my experience that csh users are the most prone to writing recipes that must be manually executed.</p>
  
  <p>--</p>
  
  <p>Perhaps I am not being clear:</p>
  
  <p>I know about</p>
  
  <pre><code> exec tcsh -c "source stuff ; exec bash"
  </code></pre>
  
  <p>and
       exec csh -c "source stuff ; exec csh"</p>
  
  <p>The situation is that I have already driven the tool, the script, a long way using "interactive" commands via Expect.</p>
  
  <p>Now, after I have done that pseudo-interactive setup, <em>finally</em> I want to return to being truly interactive.  Basically, changing the controlling terminal for the shell from the pty that Expect was using, to a real pty.</p>
  
  <p>I have been able to do this by creating a forwarding process.</p>
  
  <p>But I was hoping that I could switch.  Or do something like</p>
  
  <pre><code>... long
  ... sequence
  ... of expect commands
  exec csh -i &lt; /dev/my-pty ...
  </code></pre>