7

I need to run csh scripts from a bash shell and therefore temporary change to tcsh via a command. It works perfect in interactive mode but i cant figure out in a one line command. So in interactive mode i do in the bash shell:

tcsh

source my.tcshr

useMyTcshCmd

etc.

How can i do all of this in 1 command? Sorry for the newbie question...

user501743
  • 199
  • 1
  • 4
  • 12

3 Answers3

18
tcsh -c "echo foo; echo bar"

Result:

foo
bar

So this should work:

tcsh -c "source my.tcshr; useMyTcshCmd"
Tometzky
  • 22,573
  • 5
  • 59
  • 73
3

You should specify the interpreter directly in the script:

#!/usr/bin/tcsh
echo "doing stuff"

And then simply run the script:

./script
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
  • kind of doesnt work as it is several csh scripts interacting. And the .tcshr setup is needed first. Already spent a while trying – user501743 Nov 09 '10 at 11:10
  • You should do that inside the script. And I don't see any problem with it, I do this all the time (although I use bash, but the principle is the same). – Šimon Tóth Nov 09 '10 at 11:12
  • @user501743: In other words, use a wrapper script that sources your dot file and runs each of the other scripts. – Dennis Williamson Nov 09 '10 at 16:03
  • tcsh -c "setenv TEST bla;echo $TEST" TEST: Undefined variable. how would i do a wrapper file? tcsh -c "setenv TEST bla" echo $TEST TEST: Undefined variable. hm.... – user501743 Nov 10 '10 at 00:20
0
tcsh -c useMyTcshCmd
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • 1
    i need to source my.tcshr first, so it will be a chain of commands really. tcshr needs to set global environmet variables. – user501743 Nov 09 '10 at 11:06
  • tcsh reads .tcshrc when it runs. Not sure why you would want to name it my.tcshr. Perhaps you could include this file inside .tcshrc – Raghuram Nov 09 '10 at 11:39
  • 1
    it is not in the home dir so tcsh wont find it – user501743 Nov 09 '10 at 11:54
  • 1
    hm, so the problem is that the stuff i set in .tcshr is unavailable for further commands when i do tcsh -c "source /opt/fuelpipe/use/use-0.1.0/share/.tcshr; echo $myvar" myvar: Undefined variable. – user501743 Nov 09 '10 at 22:59
  • even this fails: tcsh -c "setenv TEST bla;echo $TEST" TEST: Undefined variable. tcsh -c "setenv TEST bla" echo $TEST TEST: Undefined variable. – user501743 Nov 10 '10 at 00:30
  • 2
    got it (use is an alias set in .tcshrc) tcsh -c "eval source /share/.tcshrc; eval use -list" – user501743 Nov 10 '10 at 01:53