How do I temporarily bypass an alias in tcsh?

11,030

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:
11,030

Related videos on Youtube

Michael
Author by

Michael

A developer, husband, father, and friend.

Updated on September 18, 2022

Comments

  • Michael
    Michael almost 2 years

    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?

  • Michael
    Michael about 13 years
    I keep getting "command: Command not found." for command, and "cd: Command not found" for \cd. Is 'command' a tcsh built-in?
  • Michael
    Michael about 13 years
    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?
  • tcoolspy
    tcoolspy about 13 years
    Sure. unalias cd.
  • geekosaur
    geekosaur about 13 years
    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.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 13 years
    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).
  • Michael
    Michael about 13 years
    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.
  • Michael
    Michael about 13 years
    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!
  • boehj
    boehj about 13 years
    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. :)
  • Mikel
    Mikel about 13 years
    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.
  • dhag
    dhag almost 9 years
    Does this work in tcsh, as the question requires? Does it work with built-in commands?