control sub-shells

Hi all,

New to shell scripting, I would like to know if it is possible to pass commands to a shell, which has been launched by a parent shell.
Example:

 
#!/bin/ksh
#
# Launch and command shells
#
. mySecondShell.ksh #this launches a sub-shell

#now is something like this possible?
mySecondShell.ksh -> ls

Problem is that I cannot edit " mySecondShell.ksh". Goal is to automate software compilation (a command in a shell) and delivery (tarring, zipping etc etc).

Thanks a lot!!

I don't understand what exactly you're trying to do but some shells like ksh93 and zsh support coprocesses,
consider the following:

$ head process*
==> process1 <==
#! /usr/dt/bin/dtksh

while :; do
  sleep 3
  read && print Received your message: $REPLY
done

==> process2 <==
#! /usr/dt/bin/dtksh

./process1 |&

while :;do
  print -p message $((++i))
  read -p
  print process1 says: $REPLY
  sleep 3
done
$ ./process2
process1 says: Received your message: message 1
process1 says: Received your message: message 2
process1 says: Received your message: message 3
^C

Thanks for the answer, but it is not exactly what I am trying to do.

One can put commands in a shell script, like 'ls' or 'touch', or one can launch a program. Now I'll launch a shell in the following line:

. mySecondShell.ksh

Everything which is written below this line will be executed only AFTER having terminated the shell "mySecondShell.ksh". But how can I say what should be done in that shell "mySecondShell.ksh"?

I still don't understand,
could you describe the actions that should be done in the parent script?
Could you also post the content of mySecondShell.ksh?

:slight_smile: But that's the problem, I don't have the contents of that shell. At least I cannot modify it.

To compile my source code for a platform, I normally launch a shell from the command line, which will set several parameters etc. This shell results in some new command-line terminal, in which I simply type 'make' to compile the plug-ins for the platform.

Now I want to launch the (let's say) platform-shell from my home-brewn shell, with the line I gave you, but then of course I cannot write the commands for the platform-shell in my home-brewn shell.

#!/bin/ksh
#
# Launch and command shells
#
. PlatformShell.ksh #this launches the platform-shell

#now this should be executed in the "PlatformShell.ksh", but how..?
make

It depends.
I understand that you cannot modify PlatformShell.ksh, but if you post the code it would be easier.

I think you need something like this (from what you're saying, it seems that the script invokes a new shell):

. PlatformShell.ksh<<!
make
!

Consider that . script is different than script and ./script.

Ok, then I think my mind needs a little refresh on the '.' (see also argument hysteresis? - Page 2 ).

I've always learned to run scripts with a '.' (so that it runs in the current shell), and to run binairies (executables) without, or with ./ if the path is not set in the .bashrc or .kshrc

ps: to run a script, one should make it executable by "chmod 777"

pps: '750' also works

I would consider always running scripts with a '.' to be a bad habit as you don't want the environment of your current shell to be modified all the time by any scripts you run.

Using ./ however is a good habit because it explicitly avoids running scripts in your PATH that you are not aware of. It is recommended over having '.' in your PATH because that could be risky if someone happened to drop a trojan called, for example, ls in your home directory, which would be run instead without you even noticing.

chmod 777 is a bad idea, as you are granting world write access. 750 or 755 are much more sensible.