Differences between revisions 5 and 9 (spanning 4 versions)
Revision 5 as of 2008-11-22 23:29:56
Size: 1516
Editor: GreyCat
Comment: first-line
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 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.

#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:
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). === Call an external utility by PATH resolution, bypassing builtins and/or functions ===
Line 40: 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)