20

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?

piCookie
  • 303
  • 1
  • 2
  • 6

3 Answers3

34

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.)

geekosaur
  • 31,429
  • 5
  • 79
  • 58
  • I keep getting "command: Command not found." for command, and "cd: Command not found" for \cd. Is 'command' a tcsh built-in? – piCookie May 06 '11 at 19:18
  • 1
    *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 06 '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 'SO- stop being evil' May 06 '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 06 '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 06 '11 at 20:23
0

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
Caleb
  • 69,278
  • 18
  • 196
  • 226
  • 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 06 '11 at 19:19
  • Sure. `unalias cd`. – Caleb May 06 '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 06 '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 06 '11 at 21:38
0

prefix your command with the word 'command'. Ex.

command ls
Weston Ganger
  • 1,856
  • 1
  • 10
  • 10
  • 2
    Does this work in tcsh, as the question requires? Does it work with built-in commands? – dhag Sep 18 '15 at 21:08