Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found a Bash script snippet earlier with which to echo a string to stderr:

echoerr() { echo "$@" 1>&2; }
echoerr hello world

This remained in my clipboard, and when I wanted to edit a file (with VIM) I accidentally pasted this snippet again instead of the file name:

vim echoerr() { echo "$@" 1>&2; }
echoerr hello world

It seems to have re-assigned echoerr to vim:

$ where vim
vim () {
    echo "$@" 1>&2;

Also, attempting to open a file with VIM now just echos the file name back:

vim path/to/some-file



What happened? (I'm running zsh inside tmux)

share|improve this question
up vote 5 down vote accepted

Because zsh allows you to define function with multiple names. From man zshmisc:

function word ... [ () ] [ term ] { list }
       word ... () [ term ] { list }
       word ... () [ term ] command
              where term is one or more newline or ;.  Define a function which
              is referenced by any one of word.  Normally, only  one  word  is
              provided;  multiple  words  are  usually only useful for setting
              traps.  The body of the function is the list between the  {  and
              }.  See the section `Functions'.
share|improve this answer

You have managed to create a function called vim(). This is possible because zsh allows you to create a single function with more than one name at the same time

% vim dud() { echo ran dud function }
% dud
ran dud function
% vim path/to/some-file
ran dud function

Note how vim() and dud() both got set as functions.

You can kill off the mistaken one by unsetting the function def for it like so:

% unset -f vim

Now vim path/to/some-file should open your editor.

share|improve this answer
+1 for unset -f, although before knowing this I just started a new terminal session. – opyate Jun 14 '14 at 10:29

Your Answer


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.