Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function with option

Status
Not open for further replies.

andrero

Technical User
Feb 11, 2002
13
NL
Hello scripters,

I'd like to make a function with a variabele option like:

f_header ()
{
echo $HEADERTEXT
}

where HEADERTEXT is the option to f_header.

this works:
HEADERTEXT="the headertext"
f_header

but I'd like to put it in one line like:
f_header ("the headertext")

Anyone have a suggestion ?

Greetings André
 
In sh and ksh:
Code:
f_header ()
{
    echo $1
}

f_header "the headertext"
Do not put any parenthesis around the argument when calling.
In fact shell function are called like shell scripts and their arguments are stored in the $1 .. $9 variable.
You can also use
Code:
shift
to get the args one by one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top