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 am using tcsh. bash and zsh and other suggestions won't help here.

I have several aliases that are named the same thing as another command, so if I did unalias it, typing the same thing would now do something different.

Most of the time I want the aliased command, which is why I have them. However, sometimes I want the unaliased command.

Without actually unaliasing and redefining the command, is there a simple way to tell tcsh to use the unaliased command instead?

For example, vi is aliased to vim, but sometimes I want to just use vi. cd is aliased to change my window title, but sometimes I want to leave it alone.

Obviously I could type /usr/bin/vi but since cd is a shell built-in command, there is no equivalent. Is there a general solution?

share|improve this question

2 Answers 2

up vote 13 down vote accepted

You can use a backslash:

% alias ls ls -a
% ls
# ls -a output here
% \ls
# plain ls output here

For shell builtins, there turns out to be a gotcha: a leading backslash prevents both aliases and builtins from being used, but an internal backslash suppresses aliasing only.

% alias cd pushd
% cd /tmp
/tmp /tmp 
% c\d
% dirs
~ /tmp

(I'm tempted to call that another argument against using the csh family of shells.)

share|improve this answer
    
I keep getting "command: Command not found." for command, and "cd: Command not found" for \cd. Is 'command' a tcsh built-in? –  piCookie May 6 '11 at 19:18
    
sigh POSIX weirdness... there are fakes in /usr/bin on here. But the manual confirms that backslash should work... and turns out it does, but you have to quote an inner character to prevent aliasing while still supporting builtins. BTW, If you're trying to do something after a cd, take a look at alias cwdcmd in tcsh(1); this also saves you from having to deal with pushd/popd etc. –  geekosaur May 6 '11 at 19:33
    
command is usually a built-in in POSIX shells, and needs to be for command -[Vv]. Using a backslash to bypass the alias only works for regular commands, not for builtins (because builtins can't be quoted in (t)csh any more than aliases can). –  Gilles May 6 '11 at 19:40
    
It seems that command is not available on my system (aside: how did you format that to stand out?), but the internal backslash works for me. Thanks! –  piCookie May 6 '11 at 20:17
    
Cheers @geekosaur - I didn't know about this \ behaviour and I think it'll be quite handy as I begin to use aliases more and more frequently. :) –  boehj May 6 '11 at 20:23

Don't make aliases that clobber shell builtins. Your life will be much easier. There are plenty of key combinations left, try cw for your change window title alias :)

Edit: Two step solution for fixing alias that aren't yours:

  1. Find the monkey who aliased cd to something other than the change-directory command and request his transfer to the oped column of the local paper. He shouldn't be holding a job where he can force ideas like that one onto other people's shells!
  2. echo unalias cd >> ~/.bashrc
share|improve this answer
    
Some of the aliases I have are not of my own doing. I appreciate your advice and will do my best to heed it where possible. Now that there are aliases I would like to bypass, how do I? –  piCookie May 6 '11 at 19:19
    
Sure. unalias cd. –  Caleb May 6 '11 at 19:31
    
Evidentally, I wasn't clear at all, Caleb, and I apologize. Let's call the 'cd' case solved. I was trying to find out how to do this for other aliases without unaliasing. I'm sorry I did not get that across. It looks like an internal backslash is exactly what I was looking for. –  piCookie May 6 '11 at 20:13
    
The cd alias might be setting the title and changing directory. That is a pretty common practice from the days before precmd and PROMPT_COMMAND. –  Mikel May 6 '11 at 21:38

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.