Stream: shorthand
Topic: detect exit code in a shell script
David Hay (Jul 17 2020 at 19:15):
What's the best way in a linux/mac shell script to detect if sushi detects errors? the 'special' variable '$?' doesn't seem to be set...
Grahame Grieve (Jul 20 2020 at 11:37):
By request of the Sushi dev team, I use the exit code
Chris Moesel (Jul 20 2020 at 14:21):
@David Hay -- it is working for me on Mac OS X.
Success:
╔════════════════════════ SUSHI RESULTS ══════════════════════════╗
║ ╭──────────┬────────────┬───────────┬─────────────┬───────────╮ ║
║ │ Profiles │ Extensions │ ValueSets │ CodeSystems │ Instances │ ║
║ ├──────────┼────────────┼───────────┼─────────────┼───────────┤ ║
║ │ 9 │ 6 │ 2 │ 4 │ 5 │ ║
║ ╰──────────┴────────────┴───────────┴─────────────┴───────────╯ ║
║ ║
║ See SUSHI-GENERATED-FILES.md for details on generated IG files. ║
╠═════════════════════════════════════════════════════════════════╣
║ Cool and So-fish-ticated! 0 Errors 0 Warnings ║
╚═════════════════════════════════════════════════════════════════╝
$ echo $?
0
Error:
╔════════════════════════ SUSHI RESULTS ══════════════════════════╗
║ ╭──────────┬────────────┬───────────┬─────────────┬───────────╮ ║
║ │ Profiles │ Extensions │ ValueSets │ CodeSystems │ Instances │ ║
║ ├──────────┼────────────┼───────────┼─────────────┼───────────┤ ║
║ │ 9 │ 6 │ 2 │ 4 │ 5 │ ║
║ ╰──────────┴────────────┴───────────┴─────────────┴───────────╯ ║
║ ║
║ See SUSHI-GENERATED-FILES.md for details on generated IG files. ║
╠═════════════════════════════════════════════════════════════════╣
║ That really smelt. 1 Error 0 Warnings ║
╚═════════════════════════════════════════════════════════════════╝
$ echo $?
1
Jose Costa Teixeira (Jul 20 2020 at 15:01):
@Chris Moesel not really related to David's question - if there are warnings, what is the exit code?
Chris Moesel (Jul 20 2020 at 15:03):
The exit code is still 0
if there are warnings. We don't want to signal an error (i.e., failure) for things that are only warnings.
Jose Costa Teixeira (Jul 20 2020 at 15:07):
perfect, thanks
David Hay (Jul 20 2020 at 18:03):
OK - I must be using it incorrectly - thanks...
David Hay (Jul 20 2020 at 18:21):
Silly me - I was 'echo-ing' a line before reading the $?...
Chris Moesel (Jul 20 2020 at 19:02):
Ha! That'll do it! Success every time!
David Hay (Jul 20 2020 at 19:15):
Exactly :)
Last updated: Apr 12 2022 at 19:14 UTC