Result of Catching Return Value from Sub_script.sh to Main_script.sh is not as Expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Result of Catching Return Value from Sub_script.sh to Main_script.sh is not as Expected
# 1  
Old 10-12-2012
Question Result of Catching Return Value from Sub_script.sh to Main_script.sh is not as Expected

Main_script.sh

Code:
#! /bin/sh

./Sub_script.sh
rc=$?
echo "Return code from Sub_script.sh : $rc"
if [ $rc -eq 991 ]; then
echo "$rc = 991" echo "" exit 1
elif [ $rc -eq 992 ]; then
echo "$rc = 992" echo "" exit 1
elif [ $rc -ne 0 ]; then
echo "$rc = 0" echo "" exit 1
fi echo "Success..." # EOF exit 0

********************

Sub_script.sh
Code:
#! /bin/sh

echo "Hello inside Sub_script.sh"
rc=$?
if [ $rc -eq 0 ]; then
echo "Sub_script.sh rc value : $rc" echo "" exit 991
fi echo "Bye..Sub_script.sh " # EOF exit 0

********************
Main Script Execution Output:
Code:
./Main_script.sh
Hello inside Sub_script.sh
Sub_script.sh rc value : 0

Return code from Sub_script.sh : 223
223 = 0

********************
Expected Main Script Execution Output:
Code:
./Main_script.sh
Hello inside Sub_script.sh
Sub_script.sh rc value : 0

Return code from Sub_script.sh : 991
991 = 0

********************
How to return a custom exit code from Sub_script.sh to Main_script.sh

Thanks a lot in Advance.

-Duddukuri

Last edited by Scrutinizer; 10-15-2012 at 02:05 AM.. Reason: code tags
# 2  
Old 10-12-2012
Exit code cannot be any arbitrary value. exit only takes integers upto 255.
Since you are exiting with a code of 991, the actual exit code is 991 % 256 = 223.
# 3  
Old 10-15-2012
Thank a lot for the Reply elixir_sinari

Is there any allowed Error Codes list which can be assigned for custom error handling?

like 245-255 range can be used for custom error reporting.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep output to file result not as expected

Hi Gurus, I run command grep ABC file1 > file2 against below file. I got all ABC_xxx in one line in file2. I expect to get multiple lines in file2. If I print result in screen, the result is expected. thanks in advance My os is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ABC_123 XXXXX... (2 Replies)
Discussion started by: green_k
2 Replies

2. Shell Programming and Scripting

Not getting expected result

Hi Experts, I have written the below script but its not working as per expectation. My requirement is if this condition ] is satisfied then only check for this condition ] if this also satisfied check for the condition ]. vi p_values.ksh path="/db/ora/files" mode=1 b_days=10... (5 Replies)
Discussion started by: nalu
5 Replies

3. Shell Programming and Scripting

Assigning variable to output gives error with expected result

Hello, I am trying to print out the first string matching query with grep and I need your help. My scenario: Database John F 4433 Street No 88 CA Elisabeth Taylor 7733 Street No 26 ON Jack Nicholson 0133 Green Park No 34 AR John F 2 9399 Southpark No 02D UT test.sh... (6 Replies)
Discussion started by: baris35
6 Replies

4. UNIX for Dummies Questions & Answers

Why my find return not expected?

root@intel_5500_server:~# find / -name bin -o -name sbin /usr/bin /usr/lib64/pm-utils/bin /usr/lib64/rpm/bin /usr/sbin /bin /sbin root@intel_5500_server:~# which ovs-pki /usr/bin/ovs-pki why below command return nothing root@intel_5500_server:~# find /... (8 Replies)
Discussion started by: yanglei_fage
8 Replies

5. Shell Programming and Scripting

Wrong result return from script

Hi Gurus, I need a script to compare two files: sample file like below: list: cde,file4 cde,file5 def,file6 def,file7 def,file8 abc,file1 abc,file2 abc,file3 acd,file9 acd,file10 tmp file1 file2 file3 file4 (12 Replies)
Discussion started by: ken6503
12 Replies

6. Shell Programming and Scripting

AWK Looping. How can I get expected result?

Can Anyone help with looping... awk 'FNR==1{i++} {for(k=1; k<=NF; k++) A=$k} # 3 Dimension Array END{ for(i=1;i<=217;i++) # For loop 2nd File 1st and 2nd column x=0;y=0 ... (18 Replies)
Discussion started by: Akshay Hegde
18 Replies

7. Shell Programming and Scripting

return value not coming as expected

Hi, We are using a shell script which is called from COBOL program. Here the program works fine till we are using MicroFocus(MF) COBOL 4 and UNIX AIX 5.3. Recently we have upgraded to MicroFocus(MF) COBOL 5.1 but same AIX version. now the shell script not working as expected. The shell... (5 Replies)
Discussion started by: vensk27
5 Replies

8. Programming

Test program not giving expected result

I have five classes. 2 composition classes,1 aggregation class and 1 dependency class.I have coded all the classes but one of my test program is not giving me the expected result.I have the following classes: TimeStamp Interval (composition of 2 TimeStamps) TimeSheet ( aggregation of many... (3 Replies)
Discussion started by: moraks007
3 Replies

9. UNIX for Advanced & Expert Users

executing script by cron doesnt give me expected result

Hi frnds... I m facing very irritating problem already waisted my 2 days.. I have a following script..( i am pasting only the main code) ftp -ivn 213.194.40.77 <<FTP user $user $password binary cd $FileDir/out lcd $localpath get $file rename $FileDir/out/$file $FileDir/tmp/$file... (1 Reply)
Discussion started by: clx
1 Replies
Login or Register to Ask a Question