0

How can I execute a pre-command in a new tcsh interactive shell?

Ex: For mimicking bash -O globstar in tcsh we can do set globstar

However, tcsh -c 'set globstar' won't work as it won't leave the interactive shell. Exits immediately after executing the command.

I need it to run a script on a remote machine where I can not modify any rc files

Assume the script is as below

      0 > cat run
      echo foo/**

With bash I can do the following

      0 > bash -O globstar run
      foo/ foo/bar foo/bar/foo foo/bar/foo/bar

I am looking for a tcsh equivalent, something like below (it obviously won't work as tcsh will not run my program)

       0 > tcsh -c 'set globstar' run

PS: I know bash -c is same as tcsh -c. I am looking for an equivalent of bash -O even if it is for limited options.

PS: This is simply tcsh version of the following question.

run bash command in new shell and stay in new shell after this command executes

Krishna
  • 924
  • 1
  • 7
  • 28

1 Answers1

0

If you are running a script, you can set any options by simply adding set option, like you would in the startup file:

#!/usr/bin/env tcsh

set globstar

# .. your code ..

For a Makefile, the same thing should work as well:

SHELL=/bin/tcsh

all:
        set noglobstar
        set

Other tan this, there is no easy way to do this other than changing a startup file. As far as I can find in the manual page there is no switch to set an option on startup, and unfortunately tcsh doesn't allow changing the startup file location with a commandline argument, either.

To avoid changing individual user's startup files, you can put the changes in the system-wide /etc/csh.cshrc. From tcsh(1):

   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 the contents of ~/.history (or
       the value of the histfile shell variable) are loaded into memory,  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  vari‐
       able. (+)

       Non-login  shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on
       startup.
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
  • Thanks @martin-tournoij. My requirement is slightly different. I have updated my question to make it more explicit. Thank you for taking time. – Krishna Oct 23 '18 at 06:46
  • Is there a reason to not add `set globstar` to the script itself @Krishna? That is probably a better way even if something like `-O` would exist, because then the script will always run, no matter how you invoke it. – Martin Tournoij Oct 23 '18 at 06:51
  • The reason is there is no script :p The actual use case (analogous to the script case) is in the Makefile We have a Makefile that uses `SHELL=tcsh`, which should be upgraded to use glob. The simple trick in bash is to use `SHELL="bash -O"` – Krishna Oct 23 '18 at 07:13
  • Well, you mentioned "script", @Krishna :-) Either way, you can just add `set globstar` to a Make target. – Martin Tournoij Oct 23 '18 at 07:22
  • I have to add it to all make targets that way :) – Krishna Oct 23 '18 at 07:29