Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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