Differences between revisions 4 and 8 (spanning 4 versions)
Revision 4 as of 2008-11-22 14:09:53
Size: 1514
Editor: localhost
Comment: converted to 1.6 markup
Revision 8 as of 2022-06-11 15:15:28
Size: 1630
Editor: ormaaj
Comment: Nuke. Create new outline
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
== How to ignore aliases or functions when running a command? == == 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). === Prioritize calling a function ===

{{{#!highlight bash
}}}
Line 40: Line 58:

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

{{{#!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 }

Prioritize calling a function

   1 

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

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)