Skip to content

How to exit a shell script using gum #351

Closed Answered by caarlos0
jbmoorhouse asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @jbmoorhouse!

Yes, this is bound to happen, as gum is another process within the script.

You can propagate it by adding a set -e, e.g.:

#!/bin/bash
set -e 
gum confirm "foo"
gum confirm "bar"
gum confirm "baz"

That means that if anything inside the script has an exit code > 0, it will fail right away, so pressing CTRL+C (or replying "no") in any of the confirms quits the entire script propagating the exit code. All this to say that, in your script, if you don't wan't the script to on, say, replying "no", you'll need to handle the exit codes.

For reference, gum confirm:

  • exit 0 on "Yes"
  • exit 1 on "No"
  • exit 130 on CTRL+C

Here's an example handling the exit codes:

#!/bin/bash
set -e

if

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@jbmoorhouse
Comment options

@mylinuxforwork
Comment options

Answer selected by jbmoorhouse
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #350 on May 04, 2023 13:44.