Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash - Returning String From Functions do I do it. I've read every tutorial i could find and all I found was some back asswards way of to 'pass-by-reference' and changing the actual variable sent to the function.

    Basically all I want to do is this, except using bash scripting
    using namespace std;          //just for you code nazi's - you know who you are
    string createSomeText()
             string x  = "Foo Bar"
             return x;
    int main()
          string text = createSomeText();
          return 0;

  2. #2
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris

    Yes, you need to get 2 features together, the first is the function itself, which you apparently know about.

    The other feature is:
    For purposes of command substitution, a command may be an external system command, an internal scripting builtin, or even a script function.

    -- the description of which you can find at:
    The Advanced Bash-Scripting Guide, noted above, is a good document to look over -- it's long, but well-worth your time ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts