How do I temporarily bypass an alias in tcsh?
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.)
Related videos on Youtube
Comments
-
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 about 13 yearsI keep getting "command: Command not found." for command, and "cd: Command not found" for \cd. Is 'command' a tcsh built-in?
-
Michael about 13 yearsSome 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 about 13 yearsSure.
unalias cd
. -
geekosaur about 13 yearssigh 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 acd
, take a look atalias cwdcmd
intcsh(1)
; this also saves you from having to deal withpushd
/popd
etc. -
Gilles 'SO- stop being evil' about 13 years
command
is usually a built-in in POSIX shells, and needs to be forcommand -[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 about 13 yearsEvidentally, 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 about 13 yearsIt 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 about 13 yearsCheers @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 about 13 yearsThe
cd
alias might be setting the title and changing directory. That is a pretty common practice from the days beforeprecmd
andPROMPT_COMMAND
. -
dhag almost 9 yearsDoes this work in tcsh, as the question requires? Does it work with built-in commands?