help-bash
[Top][All Lists]
Advanced

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

Alias inside function gives command not found


From: Khan Smith
Subject: Alias inside function gives command not found
Date: Thu, 14 Oct 2021 03:51:04 +0200

   Sent: Thursday, October 14, 2021 at 12:55 AM
   From: "Leonid Isaev (ifax)" <leonid.isaev@ifax.com>
   To: help-bash@gnu.org
   Subject: Re: Alias inside function gives command not found
   On Thu, Oct 14, 2021 at 02:48:03AM +0200, Khan Smith wrote:
   > I am in a bash function with the following code
   >
   > alias etgrep='/bin/grep'
   > etgrep -r -l "${isufx[@]}" -e "$ptrn" -- "${fdir[@]}" | sed
   > "${sta}~${stp}!d"
   > unalias etgrep
   >
   > Though everything was valid, but running the function in giving me
   >
   > bash: etgrep: command not found
   Per bash manual:
   -----8<-----
   ALIASES
   ...
   Aliases are expanded when a function definition is read, not when the
   function is executed, because a function definition is itself a
   command. As a
   consequence, aliases defined in a function are not available until
   after that
   function is executed. To be safe, always put alias definitions on a
   separate
   line, and do not use alias in compound commands.
   ...
   ----->8-----
   HTH,
   --
   Leonid Isaev


   I might be complicating this too much.  Instead I can use shell vars

GREP='/bin/grep'


reply via email to

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