Differences between revisions 7 and 8
Revision 7 as of 2009-08-30 21:09:35
Size: 1632
Editor: localhost
Comment: fix a minor error about the command builtin and some clarifications
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? ==
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:
== 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.

<<TableOfContents>>

=== Bypass aliases ===

Resolve commands normally ignoring aliases:
{{{
\name
}}}
Line 6: Line 15:
alias grep='grep --color=auto' \unalias name
name
Line 9: Line 19:
But sometimes, you need to do a one-liner with pipes where the colors mess things up. You could use any of the following: Clear all aliases:
Line 11: Line 21:
unalias grep; grep ... #1
unalias -a; grep ... #2
"grep" ... #3
\grep ... #4
command grep ... #5
\unalias -a
Line 18: Line 24:
#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. Alias expansion in bash is disabled by default in non-posix mode.
Line 20: Line 26:
#2 is similar, but removing all aliases. === Prioritize calling a builtin or external command ===
Line 22: Line 28:
#3 and #4 are the same, allowing you to run `grep` once while ignoring the `grep` alias, but not functions

#5 is different from the others in that it ignores aliases, functions, and shell keywords such as `time`. It will still prefer shell builtins like `echo` rather than /bin/echo. 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:
Bypass aliases and functions:
Line 29: 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 38: 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 41: 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)