Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error near unexpected token `(' with mv !(build)

I am trying to run the following shell command with Jenkins build process

mv !(build) build

Now the build fails saying

$ /bin/bash -xe /tmp/jenkins2925091423898519645.sh
/tmp/jenkins2925091423898519645.sh: line 2: syntax error near unexpected token `('

But the strange thing is, when running this command directly on a Jenkin slave, it works fine.

As you can see, Jenkins run the shell commands with /bin/bash -xe as well.

Any help would be appreciated because i am struggling with this for hours

like image 644
Ranil Madawalage Avatar asked Feb 02 '18 12:02

Ranil Madawalage


People also ask

What does syntax error unexpected?

A parse error: syntax error, unexpected appears when the PHP interpreter detects a missing element. Most of the time, it is caused by a missing curly bracket “}”. To solve this, it will require you to scan the entire file to find the source of the error.

What does syntax error near unexpected token `(' mean?

This error message also surfaces when you are entering commands in the Linux command line for everyday tasks such as copying files manually etc. The main reasons why this error message occurs is either because of bad syntax or problem of the OS in interpreting another system's commands/shell.


1 Answers

!(build) is an extended pattern, enabled by shopt -s extglob. It's not clear how it's being enabled in your Jenkins slave, but adding that command to your script should solve your problem.

like image 89
chepner Avatar answered Sep 16 '22 14:09

chepner