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
}
link|improve this question

56% accept rate
feedback

1 Answer

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.