LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2008, 12:40 PM   #1
Fredstar
Member
 
Registered: Jul 2004
Location: Rochester, NY
Distribution: Fedora9::FreeBSD7.1
Posts: 296

Rep: Reputation: 30
Bash String help


Hi All,

I'm not very good with bash so i need some help.
Is it possible to execute an application in bash that returns a string. And is it possible to capture the returned string in bash?

For example

Code:
#!/bin/bash
exec some_app;
If some app returns a string is there a way for me to grab it?

thanks
 
Old 09-03-2008, 12:58 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
There is no explicit way to return a string, but the next best thing is using echo at the end of a function/script and then capturing the output of the function/script in a variable:

yourFunction.sh
Code:
#!/bin/bash
...
stuff you need to do with all output suppressed
...
echo <return string>
callYourFunction.sh
Code:
#!/bin/bash
...
myVariable=`yourFunction.sh`
# or
myVariable=$(yourFunction.sh)
...
# use $myVariable
exit
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash operations with string alenD Linux - Software 6 10-17-2008 02:43 PM
String manipulation in bash dalmat Linux - Software 4 12-03-2007 05:50 PM
string manipulation in BASH ovince Programming 4 04-16-2007 07:15 PM
Bash way to tell if String is in String tongar Programming 3 06-16-2005 06:59 AM
BASH string expansions Barbarian Programming 2 11-21-2001 10:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration