BASH Function

Started by
3 comments, last by sgm 16 years, 10 months ago
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"
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]
when i do that I get this error =Hello: command not found
I think you can use $*

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

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

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

This topic is closed to new replies.

Advertisement