$ cat test.sh
set -x
# ******************************************************************************
# Find multiple version kludge
# ******************************************************************************
INSTALLED_TOVIDS=$(type -a tovid 2>>/dev/null | awk '{print $NF}' | tr '\n' ' ')
NUM_INSTALLED=0
# Only count non-links
for tovid in $INSTALLED_TOVIDS; do
if ! test -L $tovid; then
let "NUM_INSTALLED=NUM_INSTALLED+1"
fi
done
# Exit when there is more than one tovid installed
if test $NUM_INSTALLED -ne 1; then
echo "Found $NUM_INSTALLED installations of tovid on your system!"
echo "I won't run until there is only one of me :)"
echo "Installed versions:"
for version in $INSTALLED_TOVIDS; do
echo " $version"
done
echo "Exiting..."
exit 1
fi
$ bash test.sh
++ type -a tovid
++ awk '{print $NF}'
++ tr '\n' ' '
+ INSTALLED_TOVIDS='/usr/bin/tovid /usr/bin/tovid '
+ NUM_INSTALLED=0
+ for tovid in '$INSTALLED_TOVIDS'
+ test -L /usr/bin/tovid
+ let NUM_INSTALLED=NUM_INSTALLED+1
+ for tovid in '$INSTALLED_TOVIDS'
+ test -L /usr/bin/tovid
+ let NUM_INSTALLED=NUM_INSTALLED+1
+ test 2 -ne 1
+ echo 'Found 2 installations of tovid on your system!'
Found 2 installations of tovid on your system!
+ echo 'I won'\''t run until there is only one of me :)'
I won't run until there is only one of me :)
+ echo 'Installed versions:'
Installed versions:
+ for version in '$INSTALLED_TOVIDS'
+ echo ' /usr/bin/tovid'
/usr/bin/tovid
+ for version in '$INSTALLED_TOVIDS'
+ echo ' /usr/bin/tovid'
/usr/bin/tovid
+ echo Exiting...
Exiting...
+ exit 1
$ ls -la /usr/bin/tovid*
-rwxr-xr-x 1 root root 65107 Mar 12 16:59 /usr/bin/tovid
-rwxr-xr-x 1 root root 2501 Mar 12 16:59 /usr/bin/tovid-batch
-rwxr-xr-x 1 root root 17313 Mar 12 16:59 /usr/bin/tovid-init
-rwxr-xr-x 1 root root 6285 Mar 12 16:59 /usr/bin/tovid-interactive
-rwxr-xr-x 1 root root 5916 Mar 12 16:59 /usr/bin/tovid-stats
-rwxr-xr-x 1 root root 6653 Mar 12 16:59 /usr/bin/tovid-test
-rwxr-xr-x 1 root root 1363 Mar 12 16:59 /usr/bin/tovidgui