Calling a Perl script in a Bash script -Odd Situation

I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell when started and will not automatically exit. Therefore it will sit until I enter �exit�, then the application will start, but I lost the environment I need.

Simple Application Script Example:

#!/bin/bash
 
# call perl script that sets the application environment
Perl_env_script
 
# startup application
APP_START

Putting the �Perl_env_script� in the background still placed the needed environment outside the application and I don't get the environment I need when the application starts.

I also want to mention that I can manually type the command `Perl_env_script`, which leaves me in its current shell, where I can manually start the application normally. Unfortunately, this will be used from an application menu launcher and so I need to automate this process.

If this cannot be done, then I'll take the time to go through the perl script (which is huge and confusing) to gain the environment I need, but I was hoping there was an easier way.

Thanks for your help!
Frustrated Newbie

---------- Post updated at 03:23 PM ---------- Previous update was at 12:13 PM ----------

I got it working, but it's a two-step process:

I created a one-line script that calls the Perl script within an xterm:

xterm -e Perl_env_script

Once the xterm is up, the user will have to start another script to start the application:

APP_START:
#!/bin/sh
export APP_HOME=/testapps/apps
 
${APP_HOME}/bin/APPclient

I don't like the two-step process, but it is working. I might receive some complaints from users. So, if you know of a more streamlined way of doing this, please let me know.

Again, Thanks!

Hi,

Thank you for posting your own solution. I had been reading it but no idea. I hope it works without complaints :slight_smile:

Regards,
Birei

No matter how you run it, your perl script gets its own process, with its own independent set of environment variables. Children get copies of their parents' environment, nothing more. The perl script has to run your application, so it gets copies of perl's environment vars.

An environment script that can't take any arguments makes no sense. Maybe you can echo appname | perlscript ? Or perlscript appname ?

Post the contents of the environment script please.

How about running the perl script in the current shell by doing...

. /path/to/Perl_env_script

You can't run perl code in a shell...

1 Like

Thanks guys, appreciate the feedback. I'll definitely look into Corona688's suggestions.