Invoking a script within a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Invoking a script within a script
# 1  
Old 04-19-2010
Invoking a script within a script

I would like to source a script,say "B" within my own script "A", but I have the following problem, My script "A" is written in sh, while script "B" I would like to source is a tcsh script.
Directly sourcing script "B" leads to the usual "setenv: command not found" error messages. Script "B" is a system level script that I do not have edit access to. I would like to take advantage of the variables it defines and use them in my script.
Is there a direct way to do this from within my sh script ?
# 2  
Old 04-19-2010
Nope. A child cannot modify an ancestor's environment, and you'll need a child process to interpret the tcsh script.

I believe that the only possible option is to rewrite your script in tcsh (my condolences Smilie)

Regards and welcome to the forum,
Alister
# 3  
Old 04-19-2010
Rewrite script B in a real shell.
# 4  
Old 04-19-2010
Quote:
Originally Posted by cfajohnson
Rewrite script B in a real shell.
With all due respect, this is a phantastic suggestion! Wouldn't "go to hell" or "get lost" be more to the point? O/P already stated that he has no edit rights for script B, so he could only create an image of it, which over time will become outdated as script B changes.

As a last effort you could try: execute script B in a subshell (tcsh) and write the environment created this way off to a temporary file using the "printenv" or a similar command. You will have to do this within the subshell created this way. You might probably have to exclude several variables which shouldn't be changed, replace the remaining definitions by prepending "typeset -x " to all the lines and source that temporary file into your script. This doesn't look all too elegant but is IMHO the closest you can get without either rewriting your own script or script B in another shell.

I hope this helps.

bakunin
# 5  
Old 04-21-2010
Thank you bakunin for the helpful tip. I was hoping there would be a direct way to do this but it appears there isn't. I have this file redirection version in place and it works fine.

Thanks all for responding to my query.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

invoking script

hi all, is there a way to run a script upon invoking an application . for eg if i click on mozilla i want a script to run , before runniing mozilla , maybe ask a password or something only then open mozilla (2 Replies)
Discussion started by: mithun1!
2 Replies

2. Shell Programming and Scripting

Invoking a script

I am new to Unix. Could some tell me what are all the possible ways of invoking/executing a script, doesnt matter which shell you are in. Thanks (4 Replies)
Discussion started by: bobby1015
4 Replies

3. Shell Programming and Scripting

Help with invoking sed from a script

Hello I have a .sh script that needs to take a template and replace zzz in the template file with the user's name. I cannot figure out how to make the following work from my script (works from the command prompt) but not when I put it inside a *.sh script sed 's/xxx/$USER/g' template.conf >... (2 Replies)
Discussion started by: kasiolas
2 Replies

4. Shell Programming and Scripting

problem invoking Awk script

I have been writing an awk script to calculate and report on sales numbers for a couple different files. The only problem i am having is when i try to call the script. I want to invoke the script by way of awk -f report products associates sales But so far when ever I do that errors are... (2 Replies)
Discussion started by: angermanaged
2 Replies

5. Shell Programming and Scripting

pass the input to invoking script

How to pass the input to the execution script ex: test1.sh contains #! usr/bin/sh read val echo $val test2.sh contains #! /usr/bin/sh ./test1.sh now I am calling test2.sh thro command line and I want to pass the input to the script test1.sh from test2.sh ..I mean not... (6 Replies)
Discussion started by: vastare
6 Replies

6. Shell Programming and Scripting

script invoking shel script.

Hi, I have a shell script which will start a process in my prodution server. I want to write one more script as a cron job, which will start the first script at regular intervals. My question is what are the things I have to make sure to invoke the first script in second script. Can I... (3 Replies)
Discussion started by: pradeep_script
3 Replies

7. Shell Programming and Scripting

returning to the parent shell after invoking a script within a script

Hi everybody, I have a script in which I'm invoking another script which runs in a subshell. after the script is executed I want to return to the parent shell as some variables are set. However i'm unable to return to my original shell as the script which i'm calling inside is invoked in... (5 Replies)
Discussion started by: gurukottur
5 Replies

8. Shell Programming and Scripting

Invoking Shell Script via php

list me commands to invoke a shell script from php once the submit button is clicked in the php page. Requirement is Once a submit button is clicked it should run a script that displays the outcome of the script in a html/php. Please help. Thanks in Advance, BubeshJ (2 Replies)
Discussion started by: bubeshj
2 Replies

9. Shell Programming and Scripting

invoking one shell script from other

hi, i am one day old in shell scritpting. how to invoke one shell script from the other? For eg.i have two shell scripts A.sh and B.sh. Inside A.sh i need to invoke B.sh and the return code of A.sh should be the value returned by B.sh. it would be better if you provide any sample shell... (3 Replies)
Discussion started by: ajay xavier
3 Replies

10. Programming

invoking an Unix script from a C Program

How to invoke an Unix Script from C program? (or) How to invoke another C program from a C program? thanks Karthik (5 Replies)
Discussion started by: fermisoft
5 Replies
Login or Register to Ask a Question