I have the following code that checks whether either of two input args are supplied, and depending on their existance runs a certain piece of code. I'm running into syntax errors in my if statements however, because I'm getting an unexpected token `else' error
if [ -z "${4}" ] || [ -z "${5}" ]
then
echo "Missing index argument(s). Defaulting to entire file."
cat ${devicesFile} | cut -d "," -f 4 | tr [:upper:] [:lower:] | awk '{print substr($1,1,8)"-"substr($1,9,4)"-"substr($1,13,4)"-"substr($1,17,4)"-"substr($1,21,12)}' | while read deviceGuid
else
i1=${4}
i2=${5}
head -n ${i1} ${devicesFile} | tail -n ${i2} | cut -d "," -f 4 | tr [:upper:] [:lower:] | awk '{print substr($1,1,8)"-"substr($1,9,4)"-"substr($1,13,4)"-"substr($1,17,4)"-"substr($1,21,12)}' | while read deviceGuid
fi
Is it an issue with my or condition.? That's the only thing I can really think of. Any help would be greatly appreciated.
//Here's what I had before I tried to add the index parameters, so what HVD said about the broken while makes sense..
cat ${devicesFile} | cut -d "," -f 4 | tr [:upper:] [:lower:] | awk '{print substr($1,1,8)"-"substr($1,9,4)"-"substr($1,13,4)"-"substr($1,17,4)"-"substr($1,21,12)}' | while read deviceGuid
do
# now=`date +"%Y%m%d %H%M%S"`
currentTime=`date +"%H%M%S"`
currentHour=`date +"%H"`
currentDate=`date +"%Y%m%d"`
# create parent directory
mkdir -p ${crashlogFolder}/${currentDate}/${currentHour}/${crashCode}/
# create crash log for device
touch ${crashlogFolder}/${currentDate}/${currentHour}/${crashCode}/${currentTime}_${deviceGuid}.log
done
whileat the end of that pipeline on the fourth line.$devicesFileis a file on your system, you can replacecat ${devicesFile} | cut -d "," -f 4bycut -d "," -f 4 ${devicesFile}ascutcan read from file: manpages.ubuntu.com/manpages/precise/en/man1/cut.1.html