Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to use $* in a function to expand to all commandline arguments in a function, but it's giving me bizarre behavior:

$ function repeat() {
echo "$*"
}

$ repeat puts hello    # this gives me nothing at all
$ repeat "puts hello"  # this asks me for more input
repeat>

Why would it do that?

share|improve this question
    
Really weird, it's work for me in bash. Are you sure you use bash and not sh ? What's your bash version ? Mine is 4.2.37. –  GHugo Mar 25 '13 at 19:02
    
This works for me as well, but you might want to check your $IFS environment variable to make sure "$*" is expanding correctly. "When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable." –  Charles Boyd Mar 25 '13 at 19:13
2  
Are you in zsh by any chance (where repeat is a keyword). –  Stéphane Chazelas Mar 25 '13 at 19:48
add comment

1 Answer 1

up vote 9 down vote accepted

You're in zsh, not bash.

In zsh, repeat (inspired from csh repeat) is a construct used to repeat commands.

repeat 10 echo foo

Would echo foo 10 times.

If you want to call your repeat, you'd need to quote it so that it's not taken as the repeat reserved word.

$ echo $ZSH_VERSION
5.0.2
$ 'repeat'() echo "$*"
$ type -a repeat
repeat is a reserved word
repeat is a shell function
$ repeat 2 echo foo
foo
foo
$ "repeat" 2 x
2 x

Best would be to use something else for your function name though.

share|improve this answer
    
You're right: sorry. I've been working lately on several other machines where I have to work in bash, and I forgot I was using zsh on this machine. –  iconoclast Mar 26 '13 at 0:36
add comment

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.