1

I have checked the previous post on this error. still did not get the solution working. Here is my bash script. can some one help me figure out the issue . I have used https://www.shellcheck.net/ to see any error. I did not find any.

Error:

Dockerfunctiontest.sh: 2: Dockerfunctiontest.sh: Syntax error: "(" unexpected

script:

#!/bin/bash
function BuildSimpleContainer ()
{
docker search mariadb
docker pull mariadb:latest
docker run --name mariadbtestfour -e MYSQL_ROOT_PASSWORD=mypass -d mariadb --log-bin --binlog-format=MIXED
docker exec -it mariadbtest bash
apt-get -qq update
apt-get -qq -y install curl
apt-get -qq -y install wget
apt-get update
apt-get install apt-transport-https
apt-get update
cd /home
mkdir mdsd
cd mdsd/
wget '<blob url to pfx file>'
echo "certififcate Downloaded"
wget '<blob url file1>'
echo "file1 Downloaded"
wget 'blob url file2'
echo "file2 Downloaded"
}   
BuildSimpleContainer
6

My guess is that you don't run this script as a Bash script, but with some other shell, which doesn't accept this syntax. Eg. sh.

As you can see in Shellcheck, and as Bash's man on my Debian confirms, this syntax is correct:

name () compound-command [redirection]
function name [()] compound-command [redirection]

You are using the second one from the two above, and your compound-command is the contents of the {...} braces. And that's fine as far as man bash goes. But then, there are voices against this construct, as in the link in John Moon's comment below the other answer. And in the link to Greg's Wiki in that answer again.

Going back to your question, taking into consideration the name of the script, namely Dockerfunctiontest.sh, I might think you don't see much difference between sh and bash. Probably you run the script with this command:

sh Dockerfunctiontest.sh

While it would be reasonable to run it with either:

bash Dockerfunctiontest.sh

or

./Dockerfunctiontest.sh

The last one picks the interpreter basing on the first line in the script, namely:

#!/bin/bash

And while the interpreter named in the script is Bash, why not name the file the proper way?

Dockerfunctiontest.bash

Less confusion in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.