-1

My script is throwing an error in Bash:

/tmp/hudson6482258714933636361.sh: line 7: ((: i <=  : syntax error:operand expected (error token is "<=  ")
cp: cannot stat 

‘/var/jenkins_home/jobs/Latha/jobs/ShirePoc/jobs/RetrieveJob/workspace/Deploy/retrieveUnpackaged/*’: No such file or directory

Here is the script:

COUNT= $(ls -1 | wc -l)
echo $COUNT
for (( i=1 ; i <= $COUNT ; i++ ));
do
  var=package$i.xml
  echo "FILENAME is $var"
  mv -f $var package.xml
  mkdir ${WORKSPACE}/Deploy/unpackaged
  cp -R ${WORKSPACE}/tools/Package/package.xml ${WORKSPACE}/Deploy/unpackaged/
  cd ${WORKSPACE}/Deploy/unpackaged 
  cat package.xml
  ls -ltra
  cd ${WORKSPACE}/Deploy/
  ls -ltr
  ant -buildfile build.xml RetrieveComponent
done

Why is the script causing an error?

jww
  • 97,681
  • 90
  • 411
  • 885

2 Answers2

2

I believe culprit is your COUNT variable change it to as follows:

COUNT=$(ls -1 | wc -l)

Seems like you have space between = and $. Kindly check and let us know how it goes then.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
-1

In addition to RavinderSingh13 answer, also update all your variables calling as :

$i -----> ${i}

Doing this will help the kernel to understand the variable names clearly and it will interpolate the names.

Vipul
  • 1
  • 3
  • The kernel doesn't interpret the script, the shell does; and the braces are not necessary or useful for solving the OP's problem. – tripleee Feb 24 '18 at 12:10