You can use the --eval option to mongo to do this:
--eval
mongo
MASTER=`mongo --quiet --eval "db.isMaster().ismaster"`
And then test whether MASTER == "true" in your shell script.
MASTER == "true"