1

So I wanted to do a bash script but whenever I run it I get "bad substitution" error. I have already browsed stackoverflow and tried some solutions but none worked :/ Any ideas?

#!/bin/bash
printf "Hello. This is an OTS setup script provided by Damon at Otland. Please standby as user input may be required."
read -r -p "Do you want to install the webpanel? [Y/n]" response
 response=${response,,} # tolower
 if [[ $response =~ ^(yes|y| ) ]]; then
    wget https://raw.githubusercontent.com/NicolasLoew/vps/master/panelsetup.sh
    sh panelsetup.sh
 fi
 printf "If you installed webpanel please navigate to http://yourip:2004/ and follow install instructions."
 printf "Once you have installed the webpanel login and go to Enduser-->Configuration-->Apache and delete everything in the config and replace it with https://raw.githubusercontent.com/NicolasLoew/vps/master/apacheconfig. This will be needed for Znote later."
read -r -p "Do you want to compile latest TFS? [Y/n]" response
 response=${response,,} # tolower
 if [[ $response =~ ^(yes|y| ) ]]; then
    wget https://raw.githubusercontent.com/NicolasLoew/vps/master/tfsauto.sh
    sh tfsauto.sh
 fi
 printf "You have successfully compiled TFS! You can start it by going to cd forgottenserver and execute ./tfs. Dont forget to configure config.lua though. You can create database in webpanel-->enduser."
 read -r -p "Do you want to install ZnoteAAC? [Y/n]" response
 response=${response,,} # tolower
 if [[ $response =~ ^(yes|y| ) ]]; then
  wget https://raw.githubusercontent.com/NicolasLoew/vps/master/znotesetup.sh
  sh znotesetup.sh  
 fi
printf "You havee successfully setup ZnoteAAC. Navigate to http://yourip and follow the instructions."

Edit from the comments

The edit is invoked as

sh otsetup.sh 
Matteo
  • 14,696
  • 9
  • 68
  • 106
Ympker
  • 31
  • 1
  • 4
  • I ran the code and it does not give me this error.. the only change was I had to remove the space before the `#!/bin/bash` on the first line.. – vmachan Feb 08 '16 at 05:07
  • hmm. when i go to github and want to remove the space there is none. thus it seems not to be the problem :/ – Ympker Feb 08 '16 at 05:10
  • Note: The error occurs AFTER the first print was answered with y/yes.. – Ympker Feb 08 '16 at 05:13
  • Could you post the console output when you execute the script? – vmachan Feb 08 '16 at 05:17
  • After wget script I get the following: 2016-02-08 00:39:54 (570 MB/s) - 'otsetup.sh.1' saved [1527/1527] root@srv1368:~# sh otsetup.sh Hello. This is an OTS setup script provided by Damon at Otland. Please standby as user input may be required.Are you sure? [Y/n]y otsetup.sh: 4: otsetup.sh: Bad substitution root@srv1368:~# – Ympker Feb 08 '16 at 05:40

1 Answers1

3

You are invoking your script with sh and not bash.

The parameter substitution you are using to put the string to lowercase

response=${response,,} # to lower

is only available using bash from version 4.0

So either call your script with a modern bash or use a syntax that is not bash-dependant.

For example

response=$(echo "$response" | tr '[:upper:]' '[:lower:]')
Matteo
  • 14,696
  • 9
  • 68
  • 106
  • 2
    Downvote: While your diagnostics are correct, you managed to squeeze not one but *three* bugs into your "corrected" code. Try it at http://shellcheck.net/ – tripleee Feb 08 '16 at 09:34
  • @tripleee Yes, out of laziness I just did some copy and paste without really thinking about the example. Thanks for the correction. I updated the answer (even if the question is masked as duplicate it makes no sense leaving a broken answer). – Matteo Feb 08 '16 at 09:38
  • Thanks for the fix; downvote redacted. – tripleee Feb 08 '16 at 10:04