Skip to main content
added 17 characters in body
Source Link
slm
  • 379.8k
  • 127
  • 793
  • 897

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

function a-b { ... }

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

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/bin/sh not /bin/bash/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.

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.

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.

Source Link
Goblinhack
  • 493
  • 5
  • 13

Upstart and bash function names containing "-"

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.