Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Can't get bash prompts to work when running the script via curl

So, I'm running my script like this:

\curl -sSL https://raw.githubusercontent.com/mattstauffer/makeItCraft/master/makeItCraft.sh | bash

And expecting it to work like it does locally (which is fine.)

But no matter what sort of confirmation prompt I use, they all work fine locally but break over Curl.

This version:

read -r -p "[y/N] " response
case $response in
    [yY][eE][sS]|[yY]) 
        # pass
        ;;
    *)
        exit 1
        ;;
esac

Errors out with this (line 43 is the line with the [yY][eE] etc.

bash: line 43: syntax error near unexpected token `)'
bash: line 43: `    [yY][eE][sS]|[yY]) '

And this version:

read -p "[yN]" -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
    exit 1
fi

Errors out with this (line 38 is the 'if' line):

bash: line 38: f: command not found
bash: line 39: syntax error near unexpected token `then'
bash: line 39: `then'

This version:

read -p 'Do you want to Continue (yes/no?): ' answer
if [[ $answer = "y" ]]; then
    echo 'AWESOME'
else
    echo 'NOPE'
    exit 1
fi

Errors out with this (line 54 is "else"):

AWESOME
bash: line 54: syntax error near unexpected token `else'
bash: line 54: `else'

HELP! I cannot figure out ANYTHING here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment