I want to test if a clearcase view exists and execute the remove command only if it exists. I am trying to do it from a shell script in a Linux 6.x environment. I tried to format my conditions both as one-liner as well as full "if" statement, but don't seem to be able to get it to work. What do I need to do to get both - one-liner and full if syntax - approaches working?
Here is the code, in its latest state
#!/bin/ksh
#
STREAMNAME=app_stream_int
PVOB=domain_pvob
VOB=domain_app
viewdir=/opt/local/software/rational/viewstorage
shareddir=/opt/shared/test
storagedir=${shareddir}/viewstorage
projectdir=${shareddir}/projects
ctdir=/opt/rational/clearcase/bin
viewname=$viewdir/test_$STREAMNAME.vws
viewtag=test_$STREAMNAME
echo "STREAMNAME $STREAMNAME - PVOB $PVOB - VOB $VOB"
echo "Removing View if it exists ... \n"
# [ $(${ctdir}/cleartool lsview ${viewname}) ] && { ${ctdir}/cleartool rmview ${viewname}; echo "view removed" }
# [ ${ctdir}/cleartool lsview -long ${viewtag} ] && { ${ctdir}/cleartool rmview ${viewname}; echo "view removed" }
# ${ctdir}/cleartool lsview -long ${viewtag} | grep "Tag" && { ${ctdir}/cleartool rmview ${viewname}; echo "view removed" }
if [ ${ctdir}/cleartool lsview -long ${viewtag} | grep 'Tag' == "0" ]
then
echo "view found"
${ctdir}/cleartool rmview ${viewname}
fi
I would prefer a one-liner type of solution, but 'if' statement will also work.