KSH Functions String return


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH Functions String return
# 1  
Old 09-08-2008
KSH Functions String return

Hy everybody

I'm trying to write a function like

function(){
final=$1
return $final
}

but I get following error:
"return: bad non-numeric arg '[content of $final]'"

what shall I do? Isn't it possible to return strings?Smilie

thanks
lucae
# 2  
Old 09-08-2008
Print the string, and call the function with backticks. Return codes (what you can pass back with exit or return) are always numeric, in the range 0 to 255.

Code:
value=`function "fnordness"`

# 3  
Old 09-08-2008
It works, thanks a lot!

lucae from Switzerland
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh While Loop - passing variables to functions

I'm reading a text file using a while loop but when I call a function from within this loop it exits that same iteration … even though there are many more lines in the file to be read. I thought it was something to do with the IFS setting but it appears that a function call (when run... (3 Replies)
Discussion started by: user052009
3 Replies

2. Shell Programming and Scripting

ksh string replacement over a carriage return

Hi. I need to make multiple string replacements in a file but several of the strings have been broken up by a carriage return so that the first few characters are on one line and the remainder on the following line. E.g like the word 'post' in the following: Use descriptive thread... (3 Replies)
Discussion started by: Big_Jeffrey
3 Replies

3. Shell Programming and Scripting

Carriage return ksh

Hello, How do i usecarriage return in ksh. I want to do an echo "bla bla" and another echo "bla bla" will appear and replace the first echo on screen. I tried: until ; do echo "bla bla \r" done please advice. Thanks. (3 Replies)
Discussion started by: LiorAmitai
3 Replies

4. Shell Programming and Scripting

Passing array to functions in ksh script

Let me know if there is a way to pass array to a funtion in ksh script. function isPresent { typeset member member=$1 dbList=$2 echo '$1:' $1 echo '$2' $dbList The array will be at the second position....something like this isPresent 12 <array> if then echo... (3 Replies)
Discussion started by: prasperl
3 Replies

5. Shell Programming and Scripting

Get return value from PERL script calling from KSH

All: I am calling a PERL script from KSH. I need specific codes to be returned by the PERL Script. For ex: Ksh ----- result=`test.pl $FILE` My idea is to get the value of result from the test.pl, by specifically making the test.pl to print the return code. Since I had some other print... (1 Reply)
Discussion started by: ucbus
1 Replies

6. Shell Programming and Scripting

How to use string across functions in AWK

Hi , I m facing one problem with String usage in AWK . let me put what i need . i have a function and there i used one string ( meta_string) function 1 { ................... ................... meta_string = " this string got... (1 Reply)
Discussion started by: madhaviece
1 Replies

7. Shell Programming and Scripting

return string in functions

Hi friends I need to return string value in functions can anyone help me out to return string values rather than integer. #!/bin/bash add_a_user() { USER=$1 COMPANY=$2 shift; shift; echo "Adding user $USER ..." echo "$USER working in $COMPANY ..." ret_type=YES return... (1 Reply)
Discussion started by: kittusri9
1 Replies

8. UNIX for Advanced & Expert Users

How to exit the KSH functions

Hi I am having the script which contains more functions. I want to exit the function if any failure. I tried with exit - the session itself is getting logged out. How can i fix this issue? (11 Replies)
Discussion started by: sharif
11 Replies

9. Shell Programming and Scripting

ksh functions

Hi All, just wanted to ask if functions created in a Korn shell script can be passed parameters and if so what is the syntax for creating a function with parameters? thanks Mani (3 Replies)
Discussion started by: scriptingmani
3 Replies

10. Shell Programming and Scripting

Can I return a value from tclproc to my ksh script?

Hi all, I have a ksh script that calls a tcl proc that sets a variable that I am attempting to return to the calling script? Is this possible or does the tcl variable live in its own space that I cannot access from ksh. I have tried the following but when I do the var in my script is empty... (5 Replies)
Discussion started by: dfb500
5 Replies
Login or Register to Ask a Question