[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function def crash

From: Greg Wooledge
Subject: Re: function def crash
Date: Thu, 24 Jun 2021 07:17:13 -0400

On Thu, Jun 24, 2021 at 09:48:59AM +0200, Phi Debian wrote:
> $ function echo { \echo the function version; \echo "$@"; }

For the record, this isn't how you write a function that wraps a builtin.
Use the "builtin" command instead.

echo() {
  printf 'echo() wrapper invoked.\n'
  builtin echo "$@"

Or, if you aren't sure whether the command you're wrapping is a builtin
or a program, use "command":

echo() {
  printf 'echo() wrapper invoked.\n'
  command echo "$@"

The backslash hack only stops aliases from being used.  It doesn't stop
your function from calling itself recursively.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]