Differences between revisions 3 and 4
Revision 3 as of 2008-05-22 22:54:33
Size: 1513
Editor: GreyCat
Comment: clean up, adjust link
Revision 4 as of 2008-11-22 14:09:53
Size: 1514
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[Anchor(faq86)]] <<Anchor(faq86)>>
Line 39: Line 39:
See [:BashFAQ/080:FAQ #80] for more discussion of using functions instead of aliases. See [[BashFAQ/080|FAQ #80]] for more discussion of using functions instead of aliases.

How to ignore aliases or functions when running a command?

Sometimes it's useful to ignore aliases (and functions, including shell built-in functions). For example, on your system you might have this set:

alias grep='grep --color=auto'

But sometimes, you need to do a one-liner with pipes where the colors mess things up. You could use any of the following:

unalias grep; grep ...    #1
unalias -a; grep ...      #2
"grep" ...                #3
\grep ...                 #4
command grep              #5

#1 unaliases grep before using it, doing nothing if grep wasn't aliased. However, the alias is then gone for the rest of that shell session.

#2 is similar, but removing all aliases.

#3 and #4 are the same, allowing you to run grep once while ignoring the grep alias.

#5 is different from the others in that it ignores aliases and functions. It has a few options which you might want to use -- see help command.

Option #6 would be to write your function which does not commit undesirable behavior when standard output is not a terminal. Thus:

ls() {
  if test -t 1; then
    command ls -FC "$@"
  else
    command ls "$@"
  fi
}

Using this instead of alias ls='ls -FC' will turn off the special flags when the function is being used in a pipeline (or any other case where stdout isn't a terminal).

See FAQ #80 for more discussion of using functions instead of aliases.

BashFAQ/086 (last edited 2022-06-11 16:37:18 by ormaaj)