• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bash Script Help

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Phil Powell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/
 
reply
    Bookmark Topic Watch Topic
  • New Topic