I have a shell script that is getting versions of Tomcat installed on my system. I am able to print found versions to stdout using the find command. However, I am also getting output for directories and files that are not found. How can I remove this from the output and only show found files in output? Code and output is below.
Script:
#!/bin/sh
APP="Apache Tomcat"
# Common install paths to iterate over
set -- "/opt" "/usr/share" "/var" "/var/lib" "/usr" "/usr/local"
if [ -x "$(command -v unzip)" ]; then
for _i in "$@"; do
find_bootstrap=$(find $_i/tomcat*/bin/ -name bootstrap.jar)
for found in $find_bootstrap; do
get_version=$(unzip -p $found META-INF/MANIFEST.MF | grep -Eo 'Implementation-Version: [0-9].[0-9]?.[0-9]?[0-9]?' | grep -Eo '[0-9].[0-9]?.[0-9]?[0-9]?')
echo "$APP $get_version"
done
done
fi
Output:
Apache Tomcat 7.0.82
Apache Tomcat 8.5.30
Apache Tomcat 9.0.31
find: ‘/var/tomcat*/bin/’: No such file or directory
find: ‘/var/lib/tomcat*/bin/’: No such file or directory
find: ‘/usr/tomcat*/bin/’: No such file or directory
find: ‘/usr/local/tomcat*/bin/’: No such file or directory
Is there a way that I can get rid of find: ‘/var/tomcat*/bin/’: No such file or directory if no file is found.