From a post here I learned that bash (and zsh) allows a hyphen as
part of a function identifier.
Script:
f-g() { echo 2; return 2; }
f=7 g=3
echo $(( f-g ))
echo $( f-g )
c-d=9
Output:
4
2
...: c-d=9: command not found
Do you consider that a sensible extension?
On 3/18/2022 7:01 PM, Janis Papanagnou wrote:
From a post here I learned that bash (and zsh) allows a hyphen as
part of a function identifier.
Script:
f-g() { echo 2; return 2; }
f=7 g=3
echo $(( f-g ))
echo $( f-g )
c-d=9
Output:
4
2
...: c-d=9: command not found
Do you consider that a sensible extension?
No, IMHO allowing more than C symbols (alphanumeric and underscore chars starting with an alpha or underscore) for function and script names is pointless, error-prone and annoying (trying to call foo_bar when the
script is named foo-bar or vice-versa). This appears to be a case of
"what can we do" over "what should we do".
On 3/18/2022 7:01 PM, Janis Papanagnou wrote:
From a post here I learned that bash (and zsh) allows a hyphen as
part of a function identifier.
Script:
f-g() { echo 2; return 2; }
f=7 g=3
echo $(( f-g ))
echo $( f-g )
c-d=9
Output:
4
2
...: c-d=9: command not found
Do you consider that a sensible extension?
No, IMHO allowing more than C symbols (alphanumeric and underscore chars starting with an alpha or underscore) for function and script names is pointless, error-prone and annoying (trying to call foo_bar when the
script is named foo-bar or vice-versa). This appears to be a case of
"what can we do" over "what should we do".
Ed.
In comp.unix.shell, Ed Morton <mortonspam@gmail.com> wrote:
On 3/18/2022 7:01 PM, Janis Papanagnou wrote:
Script:
f-g() { echo 2; return 2; }
f=7 g=3
echo $(( f-g ))
echo $( f-g )
c-d=9
Output:
4
2
...: c-d=9: command not found
Do you consider that a sensible extension?
Yes, since shell functions and aliases may be used to replace commands
on the path, they should have the same rules for the identifiers.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 498 |
Nodes: | 16 (3 / 13) |
Uptime: | 61:16:55 |
Calls: | 9,813 |
Calls today: | 1 |
Files: | 13,754 |
Messages: | 6,191,184 |