wryun / es-shell

es: a shell with higher-order functions
http://wryun.github.io/es-shell/
Other
307 stars 25 forks source link

Allow '=' character in command arguments #41

Closed memreflect closed 2 years ago

memreflect commented 2 years ago

Closes #40, allowing GNU-style long options—e.g., --color=auto—and flags for Go programs using the flags package in its standard library—e.g., -bool-flag=false—with no need to quote or escape the = character to avoid a syntax error.

Assignment is still preferred over concatenation, so it will work as usual:

# var = '=9'
var==9

# Print 'foo=bar'
echo foo=bar

# zero-length variable name
# '' = ('=' '4')
''^==4
''^== 4
''^= = 4

# Pitfall: assignment to $echo, not echo command
# This is probably the only reason to quote '=' now.
echo =^foo
echo =foo
echo =

This change also resolves an inconsistency between bound assignment with for/let/local and unbound assignment when using keywords as variable names:

; # Before the change
; let (local = 1 2 3) {echo $local}
1 2 3
; local = 2 3 4; echo $local
syntax error

; # After the change
; let (local = 3 4 5) {echo $local}
syntax error
; local = 4 5 6; echo $local
syntax error

If you rely on such keywords as variable names, quoting them or enclosing them in parentheses during assignment will result in identical behavior, whether your es contains this change or not.