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.

I have access to a couple of remote accounts, which I mount via sshfs in subdirs of $HOME/SSHFS. In order to remind me that I'm not working with local files, I have set $PROMPT_COMMAND to a function prmt_cmd, where I set a different $PS1 if $PWD matches $HOME/SSHFS*. Now, to add a little extra protection, I'd like to add the -i flags automatically to the rm, mv and cp commands whenever I'm in a subdir of $HOME/SSHFS. So I ended up with something like

function prmt_cmd () {
if [[ $PWD == $HOME/SSHFS* ]] ; then
    PS1=some prompt
    alias rm='rm -I'
    alias mv='mv -i'
    alias cp='cp -i'
else
    # Reset the PS1, remove aliases
    PS1=my default prompt
    unalias rm mv cp
fi
}

(In the actual definition, I do some other stuff, but this is irrelevant.) However, unalias complains when the aliases do not exist, meaning that I get three error messages before each prompt when I'm not in SSHFS/*. unalias doesn't seem to have a switch to silence it. So my question is: Is there a better way to achieve what I want? Maybe I'm simply Doing It (Completely) Wrong.

In case it's relevant, $BASH_VERSION = 4.1.5(1)-release on Ubuntu 10.10.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

Just redirect the output.

unalias rm mv cp >/dev/null 2>/dev/null
share|improve this answer
    
Of course! Thanks. –  Villemoes Apr 30 '11 at 4:36
add comment

In bash you could do the following to unalias an alias only if it exists, for example rm:

[ -n "`alias -p | grep '^alias rm='`" ] && unalias rm

Another idea would be to overwrite the alias, even it if exists:

alias rm='/bin/rm'
share|improve this answer
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.