Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  24] [ 0]  / answers: 1 / hits: 53694  / 3 Years ago, mon, august 9, 2021, 4:17:11

Trying to run some bash functions , but keep encountering syntax error: "(" unexpected.
I've try'ed removing the brackets,parenthesis etc etc...nothing seems to work.



$ bash --version
GNU bash, version 4.3.46(1) release





#!/bin/bash
function hello () {
echo "Hello world"
}

More From » bash

 Answers
2

If you are running the script with sh hello.sh, the interpreting shell will not be the one mentioned in the shebang line, but /bin/sh will be used. In case of Debian and Ubuntu by default this will be dash.



So to run your script correctly with a bash, use either of the following.



/bin/bash hello.sh


or



chmod +x hello.sh
./hello.sh


Alternatively you also could set bash as the /bin/sh.



dpkg-reconfigure dash 

[#13420] Tuesday, August 10, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breadoules

Total Points: 212
Total Questions: 118
Total Answers: 120

Location: Dominica
Member since Mon, Jun 22, 2020
4 Years ago
;