huijunchen9260 / dmenufm

A simple file manager using dmenu
GNU General Public License v3.0
227 stars 15 forks source link

Non-POSIX (and generally broken) Syntax #24

Closed terminalforlife closed 4 years ago

terminalforlife commented 4 years ago

Line 146 in dmenufm:

if < "$(find "$XDGDIR1" "$XDGDIR2" -name "$appdesktop" \

I mentioned this in my last PR, but it seems it wasn't addressed. This is just outright broken. I wouldn't claim POSIX compliance until this and any other non-POSIX usages are addressed, honestly. A better wording could be "POSIX-mindful" or "POSIX-aware".

Even Bash in POSIX mode doesn't understand it. The if keyword doesn't, AFAIK, read from STDIN, which is why this is inherently broken.

huijunchen9260 commented 4 years ago

The < part is not referred to the if, but to the grep. I can adjust the code and you can see:

if grep "Terminal=false" < "$(find "$XDGDIR1" "$XDGDIR2" -name "$appdesktop" | tail -n 1)" ; then
terminalforlife commented 4 years ago

Selectshot_2019-12-17_22:22:27

Are we looking at the same thing?

I think it's best to just write it the regular way, rather than confusing people looking at your code. When I look at that, I just see that you're wanting if to read from STDIN.

By the way, this is why I say it's non-POSIX:

Selectshot_2019-12-17_22:27:38

That's yash in posixly-correct mode (good test for POSIX conformance, apparently). It should, if I'm not being blonde, be an exit status of 1, because that line is not in my .bashrc file.

Selectshot_2019-12-17_22:30:37

Now if I do the same thing in Bash in posixly-correct mode (POSIX_MODE='true'), the same thing happens. If I add the line to the file, nothing changes (although I suppose 0 would be the expected exit status at that point).

Actually, interestingly enough, even if do it in what I would personally refer to as the correct way, (if find foo | tail -n 1 | grep -q bar ..., I get the same result. There must be something else going on here, so it's possible the earlier syntax, however weird, might be valid. lol

huijunchen9260 commented 4 years ago

If statement cannot be wrong. You are either execute the command and echo yes, or not successfully execute the command, and not echo yes.

Based your screenshot, the < $(find...) grep "..." part is returning 1, so your terminal is not printing "yes". echo $? is evaluating the whole if statement, so no matter if < $(find ...) grep "..." part is correct or wrong, the if statement is always successfully echoing or not echoing yes.

Addressing to you "Actually," part, this is why no matter what command you put in the if statement, you always get 0 in echo $?.

I also downloaded yash and try to run my code with it, and everything seems to be fine.

Hope this comment can help you.

terminalforlife commented 4 years ago

Quite right, the if statement effectively protects the status from spilling out, which is why I used echo to test it, and in neither cases did it output yes. :/ Dunno what I was thinking testing the exit status of the entire statement. -_-

As for yash, I guess I'll eat a good portion of my words. I've just done the same. I got a few errors, but I think it's just because of the assumptions made in dmenufm, rather than POSIX-incorrectedness. lol Sorry for the confusion.

huijunchen9260 commented 4 years ago

OK, so I will close this issue since the misunderstanding is resolved.