[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:01:10 +0200 |
Sent: Thursday, October 14, 2021 at 12:55 AM
From: "Seth David Schoen" <schoen@loyalty.org>
To: "Khan Smith" <khansmith@mail.com>
Cc: "help-bash" <help-bash@gnu.org>
Subject: Re: Alias inside function gives command not found
Khan Smith writes:
> 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
I'm not sure why this is so in terms of bash scoping rules, but you can
make etgrep itself a function, like
etgrep() { /bin/grep "$@"; };
at which point you can use it inside of another function (including if
it was defined there). Instead of unalias, you can remove the function
binding with "unset etgrep". This should probably work as well for most
purposes.
I was doing this because I have an alias for grep that uses colour.
But
when I use grep, the file matches include the colour codes. This makes
problems when piping the grep results to ather commands.