See hudson.tasks.Shell for reference. This class is not pipeline compatible. But it does show how Jenkins invoke shell script and make it reliable and easy to troubleshoot (e.g. it creates a temp script file and execute it with -x -e mode on. It also use the system configured shell in Jenkins). Need to spend some time study Jenkins code base and see how we can improve the way we run shell scripts.