[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Alias inside function gives command not found
From: |
Leonid Isaev (ifax) |
Subject: |
Re: Alias inside function gives command not found |
Date: |
Thu, 14 Oct 2021 00:55:37 +0000 |
User-agent: |
Mutt/1.13.4 (2020-02-15) |
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