Open tejing1 opened 2 years ago
This is one of the cases where the OSH/Oil parser doesn't support it, and unless maybe we convince upstream to do it (or patch and maintain it...) we're a little stuck.
$ osh -c 'coproc TEST { echo foo; }; cat </dev/fd/${TEST[0]}'
coproc TEST { echo foo; }; cat </dev/fd/${TEST[0]}
^
[ -c flag ]:1: Unexpected right brace
I had informally reported this to Andy on the Oilshell Zulip before and he indicated that he wasn't planning to support this coproc form because it seemed like it was out in the long tail. (It's a fairly recent feature, he couldn't find many uses out in real-world programs/scripts, etc.)
I went ahead and opened an issue at https://github.com/oilshell/oil/issues/1108. Real-world use is more likely to sway Andy, so if you boiled this down from something you found in the wild, it might help to link to the script that uses it in that issue. :)
I suppose that depends on what qualifies as 'the wild'. I was using it in a personal script, so I got around the problem by rewriting it a bit. Fortunately in this case I could make it work with the unnamed simple command form. I do slightly prefer having it named, but I don't actually need it to be. I have to admit, it is a pretty uncommonly-used feature.
The script (template) I was converting is here: https://github.com/tejing1/nixos-config/blob/45d10ed6c530f80abf19e7c8e1cb028de3ebdb92/homeConfigurations/tejing/email/mailwatch.sh#L15. Don't mind the @foo@
stuff. That currently gets processed into nix storepaths by a custom system which I want to phase out in favor of resholve.
~Ah. I may be mis-remembering. It's actually the use of [name]
that causes this and not the braces, yeah?~
Nope. Braces. Phew :)
I'll link yours upstream. It's at least a real example. :)
I wrestled with this general issue a bit when I wrote lilgit; I currently try to have my cake and eat it by using the unnamed form and then copy it https://github.com/abathur/lilgit/blame/main/lilgit.bash#L3-L7.