I have a java app used to automate deployment of files. I would like to create a shell script to make the deployment from svn easier.
Currently, my script checks out the files, gets the filenames, asks for some deployment info then passes the file names to the Jar.
Usually, I can pass multiple files after the -f option, and the Jar collects each file and if the file exists, adds them into an array for processing. If the filename contains a space, I add quotation marks around the filename.
This is the input that usually works with my Jar:
java -jar deploy.jar -f 'Cancellation V2.xsl' 'Final Price.xsl' -e test
My shell script takes the file name from the end of the SVN url, adds quotation marks around the name(s) and passes to the Jar. I get this error:
'Final Price.xsl' 'Cancellation V2.xsl' not found!
Exception in thread "main" com.DeployException:
at com.ConsoleUtils.parseCommandLineArgs(ConsoleUtils.java:42)
at com.Main.main(Main.java:23)
This Exception is thrown when the Java app uses if(file.exists) on each filename before adding it to the array. This log shows that both file names are being passed as a single string, even though the shell script has formatted them correctly.
Here is my full Shell script:
#!/bin/bash
now=`date +%Y%m%d%H%M`
mkdir 'deployment-'$now
cd 'deployment-'$now
echo 'Please type tag name to deploy from:'
read tag
#svn export svn://------[removed]------
#This checks out a list of SVN urls to deploy.
j=1
for i in `cat deploy-filelist`
do
filename=$i
$j = $j++
svn export $filename
echo $filename | rev | cut -d/ -f1 | rev >> files.txt
done
echo 'loaded' $j 'files'
#svn export svn://------[removed]------
#This checks out the Jar used to deploy the files
files=''
for f in `cat files.txt`
do
filename="${f/\%20/ }"
files+="'$filename' "
done
echo $files >> files.txt
echo "Please type environment to deploy to [devl | test | etc]:"
read env
java -jar deploy.jar -f "$files" -e $env
Can anyone give me some advice on handling the file names? Why is the variable read as one String when the same format is usually ok?
Other comments aprreciated.
Thanks for reading