[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Alias inside function gives command not found
From: |
Seth David Schoen |
Subject: |
Re: Alias inside function gives command not found |
Date: |
Wed, 13 Oct 2021 17:55:54 -0700 |
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.