How to solve the version issue of Bash in my Ubuntu?

I'm trying to execute a shell script in my Ubuntu VPN terminal.

My Bash version is:

GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)

My shell script is:


I have given permissions for it like so:

chmod +x _myscript.sh
ex -sc $'%s/\r$//e|x' _myscript.sh
sh _myscript.sh

I get this error:

syntax error in conditional expression: unexpected token `(‘

which is because of lower Bash version, I found out after doing research.

The solution I found was to add this line after Bash declaration:

[code language="bash"] shopt -s extglob [/code] 

I need to know where in the script i need to give the above line.

I tried just after #!/bin/bash in my script, but I still get the same error.

  • 1
    If it doesn't work as the first line after #!/bin/bash then I would say it isn't going to work, and you should show us your actual script? – Zanna Nov 24 '16 at 12:15
  • 2
    "unexpected token '(‘ which is because of lower bash version which i found by googling." - no, almost certainly it's because you ran the script using sh _myscript.sh - sh is not bash. See DashAsBinSh – steeldriver Nov 24 '16 at 12:50

If you run a Bash script with the Bourne shell (sh), the shebang (#!/bin/bash) gets ignored, so sh runs the script, not bash. You need to run the script like this:

bash _myscript.sh
| improve this answer | |

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.