Jump to content
  • Advertisement
Sign in to follow this  
Ksingh30

BASH Function

This topic is 4055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok say you have something like this
function function_A()
{
variable=$2
}

function_A "Hello World This is a Test"
the thing is what if you want variable to equal "World This is a Test" how would you do that? variable=$2 sets variable equal to "World"

Share this post


Link to post
Share on other sites
Advertisement
Use cut(1):


function function_A() {
variable=$(echo $1 | cut -f2- -d' ' -)
}


This should be in "Everything Unix".

[Edited by - sgm on June 13, 2007 6:26:23 PM]

Share this post


Link to post
Share on other sites
I think you can use $*

It captures all the arguments to a bash script, might do the same for functions...

Share this post


Link to post
Share on other sites
Oh, oops.

There wasn't supposed to be a '$' in front of 'variable'.

(I was hacking Perl at the time, so...)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!