Score:0

Syntax check for bash script, with error code as exit code for the sake of SSH?

cn flag

I want to automate some deployment steps. Have CD server, it runs on Linux (in bash). Project is then configured to run bash script on actual app server to perform deployment. SSH is used to connect from CD runner to actual server.

Whole setup relies on an assumption that failing deployment is signaled by appropriate non zero exit code.

Want to add extra safety, so that syntax errors stop/fail deployment early. However, Bash by default do not adhere to convention of exit codes for syntax errors in script. O_O

Unfortunately "/bin/sh -n ..." will NOT return non-zero on syntax error.
Second technique tried, " $(/bin/sh -n ...) | wc -c | ... ", fails because it can not find the script file. I'm baffled by that error. Its the same file/the same command as in first technique.

Setup details:

  • CD runner running Linux & bash
  • app server running Windows & OpenSSH & bash
  • since those two are different bash installations, validation have to happen in app server bash - so over SSH

Question: Did I missed any option/flag/env variable that will instruct Bash to use non-zero exit code for syntax errors?
Or: Why would surrounding working /bin/sh invocation with $() make it fail?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.