Skip to content

Commit d0dfcc3

Browse files
committed
Fix unary operator expected error
On my system running any `mw` command after a fresh install from the AUR, I get: ``` /usr/bin/mw: line 37: [: 1.5: unary operator expected ``` Now the script doesn't error per-se but it does set the `master` and `slave` variables to wrong values. I'm also not sure how this wasn't raised before; maybe that's a new bash version thing? I'm on 5.2.37. Anyway I faffed around trying to fix this, in particular with the `-gt` operator but it turned out that properly comparing float numbers is a pain in the butt in bash. I found solutions using `bc` which I thought were weird. To keep things simple I ended up doing a little substitution on the dot `.` character and turned these nasty floats into integers, along with using the `-gt` operator which did the trick on my system. May be unorthodox so feedback is more than welcome. Thank you for the great software by the way, lots of gratitude for your work.
1 parent 943b453 commit d0dfcc3

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎bin/mw‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ alias mbsync='mbsync -c "$mbsyncrc"'
3434
# mbsync >=1.4.0 requires "Far/Near" rather than "Master/Slave."
3535
mbver="$(mbsync -v)"
3636
mbver="${mbver#* }"
37-
if [ "${mbver%.*}" >= 1.4 ]; then
37+
mbver="${mbver%.*}"
38+
# Comparing two float numbers in bash is a pain in the butt, so we get rid of
39+
# dots and turn them into nice integers
40+
mbver="${mbver/\./}"
41+
if [ "${mbver}" -gt 14 ]; then
3842
master="Far"
3943
slave="Near"
4044
else

0 commit comments

Comments
 (0)