I need to find out if a variable contains a certain text string, then do something about it.
Here is what I mean, but I don't know how to get a "contains" operator
# We have volumes called:
# /Volumes/BackupsA_K
# /Volumes/BackupsL_Z
# /Volumes/Backups_Admin
# (could be more, etc)
# Any of these volumes could be mounted, and we want to unmount it if it exists.
# We'll see if any volumes containing "Backups" is in /Volumes/
theVolume=`(ls /Volumes | grep "Backups")`
# Just to see that we're getting a full volume name
echo $theVolume
## Let's say $theVolume is Backups_Admin
if [ $theVolume CONTAINS "Backups" ]; then
unmount /Volumes/$theVolume
else
echo "No Backup Volumes Mounted"
fi
# so we need to see if $theVolume contains the word "Backups".
Thanks!!
if [[ `expr ${theVolume} : 'Backups'` -ne 0 ]]; then
echo 'found'
else
echo 'not found'
fi;
That doesn't seem to work. It's doing the "else", even though Backups_Admin is in /Volumes/
sorry 'bout that:
#!/bin/sh
theVolume='/foo/Backups'
#theVolume='/foo/Backup'
if [ `expr "${theVolume}" : '.*Backups.*'` -ne 0 ]; then
echo 'found'
else
echo 'not found'
fi;
or without using the external 'expr' - under ksh:
#!/bin/ksh
theVolume='/foo/Backups'
#theVolume='/foo/Backup'
if [[ "${theVolume}" = @(*Backups*) ]]; then
echo 'found'
else
echo 'not found'
fi;
Yeah, I don't think this is going to work. I'm os OS X and I don't have the korn shell on the client computers.
I'll figure out a way. I think all I need is the unmount command, because if the directory isn't there, then it won't really matter that unmount returns an error (logout script).
Oh well, thanks anyway!!
the first solution is NOT really a ksh solution - it will work under Bourne. I've just changed the '#!/bin/ksh' to '#!/bin/sh' - it's been a habit of mine to write everything under ksh....