?
Solved

ksh - Passing a function return value to a variable

Posted on 2003-03-05
3
Medium Priority
?
665 Views
Last Modified: 2013-12-26
I'm a Windows programmer by trade......

I have 2 books that both explain functions. Neither show how to assign a return function value to a variable. Either externally or within the same script. All examples I have found work the same as a Windows "subroutine"....returning no value. I think I'm close but don't have the correct syntax. Here's the pseudocode.
********************************
function getChars {
      var1=$1
      var2=$(var1%.*)
      return var2
}
.....
var3=$(getChars abcdefg)
********************************
In my case the function and the "call" to it are all in the same script. Can someone help me with the "syntax".."tricks"..."do's and don't's" of Korn Shell functions (ie. "Functions 101")?
Thanks...
0
Comment
Question by:GeekMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:GeekMan
ID: 8072764
This is a duplicate question please refer to first listing.
"WebMaster", please delete.
Thank you.
0
 

Accepted Solution

by:
noviceUnix earned 200 total points
ID: 8121489
Here's the syntax that you might want to use.

********************************
function getChars {
     var1=$1
     var2=$(var1%.*)
     return $var2  //put a $ sign when you need to get  
                   //the value
}
.....
Calling a function in Kornshell
getChars "abcdefg"
-------------------------------------
getChars "abcdefg"
var3=$? //var3 gets the return code value from the
        // getChars function...

Hope this helps to you...try this should work..
0
 

Author Comment

by:GeekMan
ID: 8138127
Thanks for your help
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question