
On Wed, 19 Mar 2025 at 00:35, tusooa via talk <talk@gtalug.org> wrote:
Reply is below quoted content.
On Monday, March 17, 2025 11:09:43 a.m. Eastern Daylight Saving Time Giles Orr via talk wrote:
On Mon, 17 Mar 2025 at 10:16, D. Hugh Redelmeier via talk
<talk@gtalug.org> wrote:
From: Giles Orr via talk <talk@gtalug.org>
$ gr() { grep --color=auto "$@" ; } bash: syntax error near unexpected token `('
Does this tell you anything interesting?
$ type 'gr' $ type gr
Does it ever. On all the other machines:
gr is a function gr () { grep --color=auto "$@" }
But on the machine in question:
$ type gr gr is aliased to `grep --color=auto '
(Same answer whether I ask `type 'gr'` or `type gr`.)
I was initially unable to determine where that alias was being set, but when I did `unalias gr` I could then set the "gr" function without Bash complaining, so that's clearly the problem! (The alias was being set by a very old file in /etc/ ...) Thank you so much.
I think it is because bash will expand an alias if and only if it is at the beginning of a statement. If you define the function as `function gr () { ... } `, it should not experience the same problem.
Best regards, tusooa
Let's test ... $ type gr gr is a function ... $ unset gr $ type gr bash: type: gr: not found Now I can set the alias, and then try creating a function over top of it ...: $ alias gr="grep --color=auto " $ type gr gr is aliased to `grep --color=auto ' $ function gr () { grep --color=auto "$@" ; } $ It returned silently. Perhaps you were correct?: $ type gr gr is aliased to `grep --color=auto ' So ... you were sort of correct. Saying 'function' first prevented the violent allergic response and my start-up scripts would have proceeded fine (because that step didn't error out), but the final result would still have been unexpected: my start-up scripts would have appeared to set a gr() function, but I would still have had the previously set 'gr' alias. I'm not sure if it's better in general to start with the 'function' builtin keyword, but in this case ... I would rather have seen the error as I did so I could track down and fix the error. -- Giles https://www.gilesorr.com/ gilesorr@gmail.com