Revert "Fix sh syntax"

This reverts commit cd49f9cd5d21a6592ba690cd315f19266092bee5.
Revert "Revert "Fix #3700 and other syntax issues:""

This reverts commit 4cc2ae78d3027c349969437f08a88b1fb88c9de8.