LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash String help (https://www.linuxquestions.org/questions/programming-9/bash-string-help-667329/)

Fredstar 09-03-2008 12:40 PM

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

CRC123 09-03-2008 12:58 PM

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



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