#!/bin/sh somecommand exitcode=$? if [ $exitcode -eq 0 ] then echo "Everything is O.K." else echo the exit code for somecommand was: $exitcode fi > How can I get the exit code in a bash script? > > I'm using > > if [ $? -eq 0 ] > then > echo "Everything is O.K." > else > > # want to get exit code here > fi