5

I inherited some bash scripts where the author used "-" in the function names instead of the more normal "_" e.g.:

function a-b {
...
}

Ugly but legal in bash. Problem is I sourced this inside an upstart script and got

x.sh: line 5: `a-b': not a valid identifier

Took a while to realize it was the name and not the function contents. Anyway, renaming is not an easy option in this case and as I've learned, upstart uses /bin/sh not /bin/bash to parse? run its scripts. Hence I guess this issue.

Any ideas on a workaround other than renaming?

If nothing else, at least I hope this question will warn others on the perils of odd bash coding styles and how they come back to bite you sometimes.

6

From the Upstart cookbook, Changing the Default Shell. There are 3 options, the first 2 involve changing your default shell from /bin/sh to something else. But the 3rd option looks like it would solve your particular issue.

excerpt

Use a "here document" (assuming your chosen shell supports them) within the Job Configuration Files you wish to run with a different shell:

script
/bin/bash <<EOT

echo "Hi - I am running under the bash shell"

date

echo "and so am I :)"

EOT
end script
  • That my friend is insanely useful. Many thanks. – Neil McGill Aug 23 '14 at 0:55
  • @NeilMcGill - Thanks for the Q and good luck! – slm Aug 23 '14 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.