It's possible that the commands needing sudo ran in quick enough succession. Given that I don't know the code of your bash script, the best way to find out why things aren't happening asy you expect is to run the commands in it manually in a test VM with a fresh install to find out what it's doing.
@ReillyBrogan can answer if we now enable ZSWAP by default, but I am not aware of such a change, personally.