Read Bash Script

I am very new to all these programming languages and really love Linux but have only begun to dive into bash scripting... I am curious what's going on with this script...

#!/bin/bash

if [ -e /proc/xen/capabilities ]; then
	# xen
	grep control_d /proc/xen/capabilities >& /dev/null
	if [ $? -ne 0 ]; then
	# domU -- do not run on xen PV guest
	exit 1;
	fi
fi

#safe to run mcelog
/usr/sbin/mcelog --ignorenodev --filter >> /var/log/mcelog

Thanks in advance! :cool:

Also I hope yo ucan forgive me as I just realised there is a thread for bash scripting haha PLEASE FORGIVE ME!!!!!!!!!!

See Reference Cards

-e means, check if a file or folder exists.

So, if /proc/xen/capabilities exists, it checks if the string control_d exists inside it.

If it doesn't, it quits immediately, not bothering to run the xen command on the bottom.

If it does, it doesn't quit, and continues through to the statement on the bottom.

So in effect, it only runs the statement on the bottom if control_d is found in /proc/xen/capabilities, or /proc/xen/capabilities doesn't exist.

It's done in a slightly awkward way. $? isn't needed. I'd just do this:

[ -e /proc/xen/capabilities ] && grep control_d /proc/xen/capabilities >& /dev/null || exit 1

#safe to run mcelog
/usr/sbin/mcelog --ignorenodev --filter >> /var/log/mcelog

&& is kind of a short-form if, || is a short form if-not. So, if /proc/xen/capabilities exists, AND control_d is not found inside it, exit immediately.

Awesome I can't wait until I am helping people like you! Have a great weekend!