Shell function parameter

1

Is there a way to declare and pass parameters for shell functions, like so ?

function msg( m )
{
   read -p "Task #" + m + "done. Press any key to continue
}

AntonAL

Posted 2010-04-27T10:49:58.823

Reputation: 633

Answers

3

you didn't specify which shell, but assuming bash (or zsh):

function msg() {
     read -p "Task #${1} done. Press any key to continue"
}

and then you just use it like

% msg "foobar"

with $0 - $X you acces the nth parameter, in $* and $@ you find the whole line. just check the manual of your shell.

akira

Posted 2010-04-27T10:49:58.823

Reputation: 52 754