Skip to content

Instantly share code, notes, and snippets.

@mattstauffer
Last active March 31, 2022 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattstauffer/3802d7f30b166a49eea9 to your computer and use it in GitHub Desktop.
Save mattstauffer/3802d7f30b166a49eea9 to your computer and use it in GitHub Desktop.
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.

@ahmtcn123
Copy link

Same here :D, Wow 7 years!

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