Android: How to Know if any application is already installed in android device using adb?

I've to install an android app with package name like "com.xyz.game" using adb.
I want to automate the process using shell script. The process will be like if app is already installed, uninstall it(with command adb uninstall com.xyz.game) and install using "adb install game.apk" otherwise simple "adb install game.apk".

According to (also) correct answer below, try grep the result from pm list packages.

adb shell pm list packages | grep com.your.app.package

[Original]

If the application is already installed and if you try to install the same app again, adb will return with an error - Failure [INSTALL_FAILED_ALREADY_EXISTS]. However, if you want to re-install the already installed app, then use -r parameter.

Ex:

adb install -r game.apk

Email codedump link for Android: How to Know if any application is already installed in android device using adb?