Consider the following:
$ ksh -c '1(){ echo hi;};1'
ksh: 1: invalid function name
$ dash -c '1(){ echo hi;};1'
dash: 1: Syntax error: Bad function name
$ bash -c '1(){ echo hi;};1'
bash: `1': not a valid identifier
bash: 1: command not found
$ mksh -c '1(){ echo hi;};1'
hi
Basically, I was trying to declare functions 1 and 0 which would be shorthands for true and false, but as you can see I ran into problem with using numeric names in functions. Same behavior occurs with aliases and two-digit names.
Question is "why"? Is it mandated by POSIX? or just a quirk of bourne-like shells?
See also related question to this one.
0istruein shell scripting and1isfalse(really, any non-zero is treated as false), in case anyone reading this is unaware. This is backwards from most other programming languages. – Soron Nov 19 '17 at 06:57truein shell. However, in arithmetic expansion$((...))return statuses are flipped - 1 istrueand 0 isfalsefor consistency with C-language syntax . Try for examplebash -c 'echo $((1==1));echo $((1==2))'What I was trying to do outside of this question was actually "reverse" the behavior. See the last example on my answer here to see what exactly I was trying to do. Silly idea, but nonetheless works – Sergiy Kolodyazhnyy Nov 19 '17 at 07:03$((...))is new to me. Good luck to you, then! – Soron Nov 19 '17 at 07:50