In comp.unix.shell, Ed Morton <
[email protected]> wrote:
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.
Aliases and functions seem to share nearly the same namespace that
filenames have. I use ^? and ^H as alias names to set the backspace
stty setting. The actual control characters, not the common display
form.
Ksh:
alias ="stty erase '^?'"
alias ="stty erase '^H'"
(In bash, I can set both aliases, but the ^? generates a "command not
found" error. ^H works. In ksh, both work.)
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
Variable names have a different set of rules, to be more "sensible".
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.
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".
Or you haven't thought through the "replace a command on path" use.
Bash:
$ unalias [
$ [[ $HOME ]] && echo ja
ja
$ [ $HOME ] && echo ja
ja
$ alias [=[[
$ [ $HOME ] && echo ja
bash: conditional binary operator expected
bash: syntax error near `]'
$ [ $HOME ]] && echo ja
ja
$
Ksh gives me an error trying to use [ as an alias name. Bash lets me
define and use a function [, ksh tells me the name is invalid.
Bash:
$ unalias [
$ function [ { echo yo; }
$ [
yo
$
Elijah
------
is unlikely to use exotic alias or function names except for very niche tasks
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)