I have a regular shell csh command script which has the following structure. I want to spawn new terminals and run some subsequent commands IN the new shells created.

xterm & ;
source myscript.scr; cd fred; run_tool &

xterm & ; source myscript.scr; cd bill ; run_tool &

I am running my script in a csh term called say term1. So the first part is I want to open a new terminal term2 , and then in this newly opened terminal term2 excecute the next few commands. I then also want a further terminal from the original term1 terminal and execute some other commands in this new terminal say term3

I am finding that the new terminal term2 is created , but then the commands that follow get exceuted in the original terminal term1 , NOT in the new terminal term2 .

Please can you advise as to how to ensure that my subsequent commands are "carried over " into the new shell fof execution there , noting also that I need to come back and issue a new terminal

2 Answers 2



xterm -e "myscript.scr; cd fred; run _tool" &
xterm -e "source myscript.scr; cd bull; run_tool" &

The -e switch will execute the specified command within the xterm session, rather than after it, which your example does.

From the manual page:

-e program [ arguments ... ]

This option specifies the program (and its command line arguments) to be run in the xterm window. It also sets the window title and icon name to be the basename of the program being executed if neither -T nor -n are given on the command line. This must be the last option on the command line.


I think what you want is something like this

xterm &
(source myscript.scr; cd fred; run_tool ) & 

In this case, the first command will run in the current shell session and be pushed to the background. The second command will be run in a new session generated from the current session, and also be run in the background.

However, I am a little confused by your usage of 'terminal' vs. 'shell' in the question. Are you trying to load a new interactive terminal window? Or simply run commands without affecting your current shell session?

Something I commonly do to prevent my actions from affecting my current session is this:

for my_dir in $some_list_of_dirs; do
    cd "$my_dir"
    do stuff

This way, your working directory will not be changed in the main session, only in the sub-session, and any changes you make to your environment in the sub-session will not be propagated to the main session.

  • Your suggestion will still run the scripts in the shell which invoked xterm, and not within xterm.
    – DopeGhoti
    Commented Jan 12, 2017 at 17:32
  • I am not clear on what xterm is supposed to be doing so in this case your solution may be better. Commented Jan 12, 2017 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .