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 have a script file in a directory. Its contents are as follows :

#!/bin/bash                                                                                                                                                                                       

function set {

    cur=`pwd`

    alias m="cd $cur/app/models"
    alias v="cd $cur/app/views"
    alias t="cd $cur/app/views/templates"
    alias c="cd $cur/app/controllers"
    alias cl="cd $cur/app/classes"

    alias con="cd $cur/config"
    alias p="cd $cur/public"
}

function unset {
    unalias m v t c cl con p
}

if [ $1 = 's' ]; then
    set 
elif [ $1 = 'u' ]; then
    unset
fi

When I haven't yet sourced this file, there is no problem. However, once I source this file using the command . script.sh, whenever I type a command like cd or vim and then type something and press the tab button, this is what I get :

cd abash: unalias: m: not found
bash: unalias: v: not found
bash: unalias: t: not found
bash: unalias: c: not found
bash: unalias: cl: not found
bash: unalias: con: not found
bash: unalias: p: not found
bash: _upvars: -v: missing argument(s)
bash: unalias: m: not found
bash: unalias: v: not found
bash: unalias: t: not found
bash: unalias: c: not found
bash: unalias: cl: not found
bash: unalias: con: not found
bash: unalias: p: not found
bash: _upvars: -v: missing argument(s)

Any idea what happens and how to stop it?

share|improve this question
    
BY the way, setting aliases like this is not a good idea either. See here for more info. –  terdon Feb 11 at 18:24

1 Answer 1

up vote 2 down vote accepted

You're defining functions called set and unset. This is a really bad idea, because your complection module seems to call set or unset (which are part of POSIX), expecting to use the shell builtins, but it ends up getting your function instead.

Name your functions something else other than set and unset (if you really must name them that, prepend an underscore).

As an aside, there's no reason to create functions as function foo { ... }. Just use foo() { ... } instead -- it's part of POSIX, whereas the form you are using is not.

share|improve this answer
1  
The same thing could be said for set as well, which is also a POSIX built-in. –  jw013 Feb 11 at 15:33
    
Wow! I didn't know about that. Should have noted the syntax highlighting. Thanks guys :) –  kevin Feb 11 at 15:34

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.