wryun / es-shell

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

Echo in redefined %parse confuses things #10

Closed wryun closed 2 years ago

wryun commented 9 years ago
emmachisit:~; let (parse=$fn-%parse) fn %parse prompt1 prompt2 { echo -n X; cmd = <={$parse $^prompt1 $^prompt2}; echo -n Z; return $cmd; }
Xemmachisit:~; x=`{es -c 'echo $0'}
ZXemmachisit:~; echo $x
ZXZes X
Xemmachisit:~; echo $x(1)
ZXZes
Xemmachisit:~; echo $x(2)
ZX
Xemmachisit:~; echo $x(3)
Z
memreflect commented 2 years ago

I realize this is pretty old, so you might have already figured out what's going on, but it is because fn-%parse was exported. To get x = es, there are two remedies I can think of immediately:

You might know this trick already, but I tend to use something like printf '<<%s>>\n' $x to try making sense of confusing shell output like this, especially when I might be dealing with whitespace issues:

emmachisit:~; let (parse = $fn-%parse) fn %parse prompt1 prompt2 {echo -n X; cmd = <={$parse $^prompt1 $^prompt2}; echo -n Z; return $cmd; }
Xemmachisit:~; x = `{./es -c 'echo $0'}
ZXemmachisit:~; printf '<<%s>>\n' $x
Z<<XZ./es>>
<<X>>
wryun commented 2 years ago

Right, not sure how I missed that it was exported. I guess I thought there was something more complex going on. Thanks for explaining - and the printf suggestion is indeed a good one.