I have an exe which takes 2 parameters both are csv as below splitline.exe /dir/file1.csv /dir1/file2.csv, this basically splits the lines in the input file to 2 lines in the output file.So,I wrote a shell script to execute this exe. the directory is fixed,but the filename can differ, both filename in src directory and destination directory should be same.I am running it on windows environment.It is having MKS installed,so unix and shell script also can be executed. Below is the code snippet which I wrote:
#!/bin/sh
srcdir='D:/srcdir/srcdir1/'
destdir='D:/destdir/destdir1/'
extension='csv'
srcfile='${srcdir}/*.csv'
if [[-f ${srcfile} in ${srcdir}]]
then
cSplit.exe "${srcdir}/{srcfile}.${extension}" "${destdir}/${srcfile}.${extension}"
mv "${srcfile}" "${srcdir}/old"
else
echo "no file"
fi
output: [[-f : splitty.sh 21 not found Its giving output as "no file" Please correct my mistake,as I am new to shell script
How about this template:
Note 1: If you are using Windows, then using
/is OK inbash; but the commandcSplit.exemay not accept/as directory delimiter. I am not using Windows, so I cannot check that.Note 2: I do not really know Windows, so I tried NOT to use other commands like
basename, orfind, etc. As for drive nameD:please check. Maybe it is mapped to/mnt/dor something.Note 3: I've fixed the script based on Charles comments.