File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Bash Script Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Bash Script Help" Watch "Bash Script Help" New topic
Author

Bash Script Help

Phil Powell
Greenhorn

Joined: Jul 13, 2004
Posts: 26
I am brand-spankin' new to Bash script from a web programming background, so my questions are going to, perhaps, sound "ignert" at best, but understand, I come from a TCL/PHP/Java/ASP background so I'm accustomed to All Things Web

Having said that, I need help. I wrote a bash script function that will return a string (or whatever bash comes closest to doing "return" as) and needs to return it into a variable that I will use later.

Here is the function:



Problem is that I have no clue as to how to capture the return of this function.

does not work
also does not work
also does not work
also does not work
[CODE excludedList=`echo \\`tarExcludedList\\''[/CODE].. you guessed it.

What do I do? I want to return the last line of tarExcludedList into a variable and have no clue how.

Help appreciated

Thanx
Phil
Phil Powell
Greenhorn

Joined: Jul 13, 2004
Posts: 26
BTW I figured out I was using the wrong function name, nonetheless, nothing still works, I cannot output the function results no matter what I try.

I know in TCL it's this



In PHP it's this



and in Java it would be a string return that I just do



Ok, so how is it done in Bash?

Phil
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

perhaps only your test was wrong?
how did you test?

did you capture in the same script?
In another script?
From commandline?

in the script, you have to call the function.
But then you could assign a global variable to the result, and use the variable.

from shell:

should work, or better:


but then the script needs to call the function.

Else you could source the script, and call it on your own:


From commandline


http://home.arcor.de/hirnstrom/bewerbung
Phil Powell
Greenhorn

Joined: Jul 13, 2004
Posts: 26
Perhaps what I don't understand is the fact that bash script seems to have no concept of scope that I can fathom. Assigning a global variable failed upon doing so.

What I wound up doing was throwing out a weird code snippet that worked:



Where $excludedList was a variable set in the function that, for some wacko reason, becomes instantly global. This is nowhere near what I'm used to in any programming language so I never would have guessed that one.

Phil
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I didn't work much with functions in scripts.

A very good tutorial with much more answers than I can give might be found here:http://freshmeat.net/projects/advancedbashscriptingguide/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bash Script Help
 
Similar Threads
Reading from a file and adding it to array using ksh...
POST data w/o form?
this="${0##*/}"
How to interact with bash?
echo javascript within php script.