chmod symbolic notation: unexpected “=” operation behavior-Collection of common programming errors

To build upon and/or clarify Davidw’s answer:  Since you’re saying g=, you are asking for only the group permissions to be changed.  If you would say chmod =x foo, you would get ---x--x--x.  If you want to get ------x---, do

chmod =,g=x foo

This is the same as

chmod  =  foo
chmod g=x foo

The first command sets the permissions to 0 (----------), because it sets all three user groups (u, g, and o) to no access, and I guess by now you understand what the second one does.  As indicated, you can concatenate operations by separating them with commas.

I understand that to have execution permission you have to have read permission, so the read permission for the group is needed, .

This is true only if you’re talking about a script.  A (compiled) binary executable can be run with only execute permission.