How to return a value from another script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to return a value from another script
# 1  
Old 01-07-2010
How to return a value from another script

Hi!

I have a parameter in an existing script, let's call the parameter param1 and the script - script1.

I have another script - script2, which receives param1 and returns a certain value.

I would like this value to be returned inside param1.

There is no problem with script2, it runs perfectly.

I tried many things like

@ param1 = `script2 $param1`
this one returns an error: "script2: command not found."

or
@ param1 = `echo script2 $param1`
this one returns an error: "@: expression syntax."

or
@ param1 = `script2 param1`
this one returns: "script2: no match."

or
@ param1 = `echo script2 param1`
this one returns: "echo: no match."

If you have any idea on how to solve this, please reply to this thread.

Thank you and have a nice weekend,
Shira. Smilie
# 2  
Old 01-07-2010
Replace
Code:
@ param1 = `script2 $param1`

with

Code:
@ param1 = `perl script2  $param1`

Also if script1 and script2 are not in the same dir from which you are executing the script then use the full path of the script.

Note : i assume script2 is a perl script , hence used perl. If its in some other language define the appropriate usage

HTH,
PL
# 3  
Old 01-07-2010
Hi!

Thanks for the reply!
Actually I'm not using perl but csh.

The files are in the same path.

I actually did this kind of thing once, but I forgot how to do it.
But I'm sure that it wasn't that way.

I thought about doing some pipelining but it didn't succeed as well...

Thanks,
Shira.
# 4  
Old 01-07-2010
Hi shira ,

Code:
@ param1 = `script2 $param1`
this one returns an error: "script2: command not found."

This means that shell is not able to execute the script.

Normally when you run the script from the command line you use

Eg:- sh test_script.sh or
./test_script.sh


similarly when using the backtick operator use the appropriate usage

HTH,
PL
# 5  
Old 01-07-2010
Hi,

I just found out what was my problem:
I needed to add "./".

So the correct answer is:

@ param1 = `./script2 $param1`

Thanks for the patience and the help,
Shira. Smilie
# 6  
Old 01-08-2010
You can also do

Code:
source scriptname

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

2. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

Hi, I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed. Below is my sample... (14 Replies)
Discussion started by: Prathmesh
14 Replies

3. Shell Programming and Scripting

Doing a tail in a script and then return back and continue script

Hello all, I am trying to do a tail in a script. But when I quit the tail my script quits also. This is not what I want. I am struggling to get this done. #!/bin/bash askFile() { echo -n "Enter file: " read FILE } doTail() { tail -F "${1}" } askFile doTail... (4 Replies)
Discussion started by: markdark
4 Replies

4. Shell Programming and Scripting

How to return a value of a variable from shell script to perl script

HI , Is there any way to return a value of variable from shell to perl script. Code: === Perl file my $diff1=system("sh diff.sh"); my $diff2=system("sh diff1.sh"); I need exit status of below commands i.e 0 and 1 respectively. Since in both the cases diff is working so system... (3 Replies)
Discussion started by: srkelect
3 Replies

5. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

6. Shell Programming and Scripting

how ro use return from a child script

I use return <value> to return a value from inside an else condition in child script to parent script and i am getting the following error.What is this sourced script? Can I return value to a different script using return statement. return: can only `return' from a function or sourced script (1 Reply)
Discussion started by: codeman007
1 Replies

7. Shell Programming and Scripting

How to know return value of the script

I have a script and when it is running it is showing PASSED or FAILED.But I would like to pass the results into return code.So pls provide suggession how to add return code into this script AgcfIp=`GetSoftatcValue AgcfIp_1` AgcfShell=`GetSoftatcValue AgcfShell_1` AgcfPath=`GetSoftatcValue... (2 Replies)
Discussion started by: madhusmita
2 Replies

8. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

9. Shell Programming and Scripting

script to return value

I have 3 scripts script A - wrapper script to disguise invoker true identity script B - perform database operation and return a value (either W/H) -> return value by echoing the result script C - use script A to mask as the database owner then invoke script B to retrieve the value ... (1 Reply)
Discussion started by: mpang_
1 Replies

10. Shell Programming and Scripting

return valuse from child script to parent script

Hi, I am trying to return a value from child script to a parent script just as a function does. The child script will look for a file and if exists will return 1 else 0. I need to capture the status 1 from child script in the parent script and proceed further. if 0, i need not do... (1 Reply)
Discussion started by: borncrazy
1 Replies
Login or Register to Ask a Question