1

I don't understand what's wrong.

When executing a bash script via wget or curl the script aborts with a syntax error. Although it works if downloaded and executed as a local file bash script.sh.

wget -O- https://domain.com/script.sh | bash

curl https://domain.com/script.sh | bash

Error:

bash: line 114: syntax error near unexpected token "fi"

This is the code:

...

while [[ ! $db_database ]]; do
  echo
  read -p "MySQL Database: " db_database
done

if [[ -z $db_prefix ]]; then
  echo
  read -p "MySQL Table Prefix [lc_]: " db_prefix
  if [[ ! $db_prefix ]]; then
    db_prefix="lc_"
  fi                 # <-- This is the line, 114
fi

if [[ -z $db_collation ]]; then
  echo
  read -p "MySQL Collation [utf8_swedish_ci]: " db_collation
  if [[ ! $db_collation ]]; then
    db_collation="utf8_swedish_ci"
  fi
fi

...

1 Answer 1

3

The problem is the read which expects to read from stdin, and that fails when you're piping (it fails to read what you are expecting to read and instead reads the text of the actual script, which is being piped in on standard input, causing the syntax error by effectively deleting the line after the read statement from the script). So use command substitution instead to execute the contents inline:

bash -c "$(curl https://domain.com/script.sh)"

Or

bash -c "$(wget -O- https://domain.com/script.sh)"
3
  • I tried bash "$(curl raw.githubusercontent.com/litecart/installer/master/cli/…)" and instead got the error Filename too long.
    – tim
    Jun 19, 2020 at 15:20
  • @tim sorry, please try the updated answer, I had forgotten the -c.
    – terdon
    Jun 19, 2020 at 15:37
  • @terdon It works! Thank you sooo much! I never could have figured that one out myself. :)
    – tim
    Jun 19, 2020 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .