Sponsored Content
Top Forums Shell Programming and Scripting Returning multiple values in Shell Post 302800189 by Priya Amaresh on Monday 29th of April 2013 07:11:36 AM
Old 04-29-2013
Returning multiple values in Shell

Hi

I have a code as the following
Code:
#!/usr/bin/ksh
set -x
row()
{
a=$1
b=$2
c=$(($a + $b))
d=$(($a * $b))
echo $a $b
}
e=`row 2 3`
set $e
echo "The value of c is $c"
echo "The value of d is $d"

My requirement is I need to pass two arguments to a function and return two values calculated from that function..

When i tried to execute the same
i got the output as
Code:
# ./testg.sh
+ + row 2 3
e=2 3
+ set 2 3
+ echo The value of c is
The value of c is
+ echo The value of d is
The value of d is

Please help.. Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Returning Values (shell Script)

I have an application on Informix 4GL, and I am invoking the shell script from the program, but I need to know if the shell script work fine or not, in order to continue the process. I know that we can use $? to get the final status but this is on unix command. How can I return a value from the... (3 Replies)
Discussion started by: jennifer01
3 Replies

2. Shell Programming and Scripting

Returning values from child to parent shell

I need to send the status from child shell failure to parent shell. I would like to know how could we accomplish this. My parent.sh is as below: #!/bin/ksh set -x echo "I am in parent shell now..." child.sh ret_stat=$? echo "rest_stat=$ret_stat" echo "I am below parent shell end..." ... (4 Replies)
Discussion started by: acheepi
4 Replies

3. Solaris

awk/nawk returning decimal values?

Hi Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. ... (1 Reply)
Discussion started by: moutaye
1 Replies

4. Shell Programming and Scripting

awk/nawk returning decimal values?

Hi Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. ... (1 Reply)
Discussion started by: moutaye
1 Replies

5. Programming

returning multiple values from a function in C

hi how can I return multiple values from a C function. I tried the following: #include <stdio.h> void foo(int id, char *first_name, char *last_name) { /* this is just an example to illustrate my problem... real code makes use of the "id" parameter. */ first_name = (char... (8 Replies)
Discussion started by: Andrewkl
8 Replies

6. UNIX for Dummies Questions & Answers

For loop returning more values

Hi All, Thanks all of you for the help you provide to me. Well, I have one more problem, where I am trying to pull file system information in the loop and display the filesystem percentege. I am using following code to achive this, nut it's giving the weired output. My file system is ... (1 Reply)
Discussion started by: alok.behria
1 Replies

7. Shell Programming and Scripting

error in shell script while returning values-- urgent issue plz help.

Hi, I have initailized a varaible EBID as typeset Long EBID=0 i am calculating value of EBID using certian formula as below: (( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE )) return $CURR_EBID The output is as below: + (( CURR_EBID=... (6 Replies)
Discussion started by: kasanur
6 Replies

8. Shell Programming and Scripting

Output breaking when returning multiple values

I've been trying to write a command-line function to grab a website's MX records and their ip addresses. The code below works with domains that only have one MX record: function kmx { mx=`host -t MX $1 | awk '{ print $7 }'`; ip=`host $mx | sed '/IPv6/d;/handled/d' | awk '{ print $4 }'`; ... (8 Replies)
Discussion started by: Azrael
8 Replies

9. Shell Programming and Scripting

Returning and capturing multiple return values from a function

Hi I am pretty confused in returning and capturing multiple values i have defined a function which should return values "total, difference" i have used as #!/usr/bin/ksh calc() { total=$1+$2 echo "$total" diff=$2-$1 echo "$diff" } I have invoked this function as calc 5 8 Now i... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

10. Programming

Perl subroutine returning different values in HPUX

HI , I am running a program on hpux in perl. I am encountering a strange issue where when i print a variable in the sub which is returning it , it prints a different value but when i call it and store value in a variable it gives a different o/p. the sub is sub CheckConfigFilePattern ... (4 Replies)
Discussion started by: Jcpratap
4 Replies
MSSQL_FETCH_ASSOC(3)													      MSSQL_FETCH_ASSOC(3)

mssql_fetch_assoc - Returns an associative array of the current row in the result

SYNOPSIS
array mssql_fetch_assoc (resource $result_id) DESCRIPTION
Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. mssql_fetch_assoc(3) is equiv- alent to calling mssql_fetch_array(3) with MSSQL_ASSOC for the optional second parameter. PARAMETERS
o $result_id - The result resource that is being evaluated. This result comes from a call to mssql_query(3). RETURN VALUES
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows. EXAMPLES
Example #1 mssql_fetch_assoc(3) example <?php // Send a select query to MSSQL $query = mssql_query('SELECT [username], [name] FROM [php].[dbo].[userlist]'); // Check if there were any records if (!mssql_num_rows($query)) { echo 'No records found'; } else { // Print a nice list of users in the format of: // * name (username) echo '<ul>'; while ($row = mssql_fetch_assoc($query)) { echo '<li>' . $row['name'] . ' (' . $row['username'] . ')</li>'; } echo '</ul>'; } // Free the query result mssql_free_result($query); ?> PHP Documentation Group MSSQL_FETCH_ASSOC(3)
All times are GMT -4. The time now is 01:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy