Hour 11

1: What is the difference between the following commands?
if [ -e /usr/local/bin/bash ] ; then /usr/local/bin/bash ; fi
if [ -x /usr/local/bin/bash ] ; then /usr/local/bin/bash ; fi
A1: The difference is that the first command will try to run the command without checking if it is executable. Thus if the file exists but is not executable, the command will fail. The second command takes this into account and attempts to run the command only if it is executable.
2: Given the following variable declarations,
HOME=/home/ranga
BINDIR=/home/ranga/bin

what is the output of the following if statement?

if [ $HOME/bin = $BINDIR ] ; then
    echo "Your binaries are stored in your home directory."
fi
A2: The output is
 Your binaries are stored in your ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.