Differences between revisions 3 and 9 (spanning 6 versions)
Revision 3 as of 2008-05-22 22:54:33
Size: 1513
Editor: GreyCat
Comment: clean up, adjust link
Revision 9 as of 2022-06-11 16:37:18
Size: 1471
Editor: ormaaj
Comment: calling a function section not really necessary (I think)
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[Anchor(faq86)]]
== How to ignore aliases or functions when running a command? ==
<<Anchor(faq86)>>
== How to ignore aliases, functions, or builtins when running a command? ==
functions, builtins, external utilities, and aliases can all be defined with the same name at once. It's sometimes necessary specify which of these the shell should resolve while bypassing the others.
Line 4: Line 5:
Sometimes it's useful to ignore `alias`es (and functions, including shell built-in functions). For example, on your system you might have this set: <<TableOfContents>>

=== Bypass aliases ===

Resolve commands normally ignoring aliases:
Line 6: Line 11:
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
\name
Line 17: Line 14:
#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. {{{
\unalias name
name
}}}
Line 19: Line 19:
#2 is similar, but removing all aliases. Clear all aliases:
{{{
\unalias -a
}}}
Line 21: Line 24:
#3 and #4 are the same, allowing you to run `grep` once while ignoring the `grep` alias. Alias expansion in bash is disabled by default in non-posix mode.
Line 23: Line 26:
#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`. === Prioritize calling a builtin or external command ===
Line 25: Line 28:
Option #6 would be to write your function which does ''not'' commit undesirable behavior when standard output is not a terminal. Thus: Bypass aliases and functions:
Line 28: Line 31:
ls() {
  if test -t 1; then
    command ls -FC "$@"
  else
    command ls "$@"
  fi
\command name
}}}

If `PATH` is unknown / unreliable:

{{{#!highlight bash
\command -p -- name "${args[@]}"
}}}

The remainder of this FAQ assumes alias expansion has been disabled or otherwise mitigated.

=== Prioritize calling only a builtin ===

{{{#!highlight bash
# Strictly bash-only. Not recommended

function my_builtin {
    builtin my_builtin "$@"
Line 37: Line 52:
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). === Call an external utility by PATH resolution, bypassing builtins and/or functions ===
Line 39: Line 54:
See [:BashFAQ/080:FAQ #80] for more discussion of using functions instead of aliases. {{{#!highlight bash
"$(type -P name)" "${args[@]}"
}}}

=== Call a specific external utility ===

Specify the full or relative path name containing at least one forward slash.

=== See also ===

 * https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01_01
 * https://burnthewhich.github.io/

How to ignore aliases, functions, or builtins when running a command?

functions, builtins, external utilities, and aliases can all be defined with the same name at once. It's sometimes necessary specify which of these the shell should resolve while bypassing the others.

Bypass aliases

Resolve commands normally ignoring aliases:

\name

\unalias name
name

Clear all aliases:

\unalias -a

Alias expansion in bash is disabled by default in non-posix mode.

Prioritize calling a builtin or external command

Bypass aliases and functions:

\command name

If PATH is unknown / unreliable:

   1 \command -p -- name "${args[@]}"

The remainder of this FAQ assumes alias expansion has been disabled or otherwise mitigated.

Prioritize calling only a builtin

   1 # Strictly bash-only. Not recommended
   2 
   3 function my_builtin {
   4     builtin my_builtin "$@"
   5 }

Call an external utility by PATH resolution, bypassing builtins and/or functions

   1 "$(type -P name)" "${args[@]}"

Call a specific external utility

Specify the full or relative path name containing at least one forward slash.

See also

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