eradman/entr

$0 isn't populated on macOS when using -s

semanticart opened this issue · 5 comments

I love entr. Thank you for creating and maintaining it. ❤️

It appears there's a bug where $0 isn't populated with the first file to trigger an event. /_ works fine.

I'm on 14.2.1 (23C71) and using entr based on main (though I've tried 5.4 and 5.3 releases as well and they're similarly affected)

In this example, /_ works as expected.

» ls | entr echo /_
/Users/ship/Library/CloudStorage/Dropbox/neuron/16d9dc5f.md
/Users/ship/Library/CloudStorage/Dropbox/neuron/fx.md
/Users/ship/Library/CloudStorage/Dropbox/neuron/fx.md

For fish shell, $0 doesn't populate.

» ls | entr -s "echo $0"

fish returned exit code 0

fish returned exit code 0

fish returned exit code 0

bash and zsh both show their respective shell names/paths when I try from within one of those shells

ship@ship neuron % ls | entr -s "echo $0"

/bin/zsh
zsh returned exit code 0
/bin/zsh
zsh returned exit code 0

Please LMK if there's something I can do to help diagnose this further or if I'm using this wrong. Thanks!

Glad you like it!

It appears that fish -c doesn't set $N based on supplied arguments

$ fish -c 'echo $0' one

Where as bash, ash, ksh, sh do:

$ sh -c 'echo $0' one
one

Does fish use an alternate convention for passing variables?

Indeed it does.

fish -c 'echo $argv[1]' one

This works as expected (array indices start at 1 instead of 0).

This still doesn't work though

ls | entr -s "echo $argv[1]"

And neither does the bash equivalent

$ export SHELL=/opt/homebrew/bin/bash
$ ls | entr -s "echo $0"

bash returned exit code 0

bash returned exit code 0

🤔 Is ls | entr -s "echo $0" a valid test for bash/sh/etc? If not, what should I be doing instead?

Ah, make sure you use single quotes! When you use double-quotes variables are evaluated before entr runs.

@eradman That works! TYSM for helping me debug this. That behavior makes sense in retrospect.

I know what one chooses to include/exclude in the manual page is always a balance, but do you think this single quote caveat might be worth including? (I am happy to concede that the fish-specific behavior is probably not worth including)

Cool! Closing

The man page isn't the right place to hilight shell nuances. But I'd be happy to add hints on avoiding shell pitfalls to http://eradman.com/entrproject/

Feel free to suggest a new section or edits to that page.