Differences between revisions 2 and 3
Revision 2 as of 2007-10-11 21:02:20
Size: 1511
Editor: GreyCat
Comment:
Revision 3 as of 2008-05-22 22:54:33
Size: 1513
Editor: GreyCat
Comment: clean up, adjust link
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
#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. #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.
Line 21: Line 21:
#3 and #4 are the same, allowing you to run grep once while ignoring the grep alias. #3 and #4 are the same, allowing you to run `grep` once while ignoring the `grep` alias.
Line 23: Line 23:
#5 is different from the others in that ignores aliases '''and''' functions. It has a few options which you might want to use, see `help command`. #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`.
Line 25: Line 25:
Option #6 would be to write your function such that it does ''not'' commit undesirable behavior when standard output is not a terminal. Thus: Option #6 would be to write your function which does ''not'' commit undesirable behavior when standard output is not a terminal. Thus:
Line 39: Line 39:
See [:BashFAQ#faq80: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.

Anchor(faq86)

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 [:BashFAQ/080:FAQ #80] for more discussion of using functions instead of aliases.

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