bash Cheat Sheet

Test grep result

grep "somestring" somefile
if [ "$?" -eq 0 ];
then
	echo "processing somefile"
fi

Test environment variable

if [ -n "${ENV_VAR+x}" ]
then
	... do something ...
else
	... do something else ...
fi

Test if a program is installed

if which program >/dev/null; then
    echo program found
else
    echo program not found
    exit 1
fi
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s