Download Learning the bash Shell, 3rd Edition
Transcript
statement. If the status is 0, the condition evaluates to
true; if it is anything else, the condition is considered
false. The same is true for each condition attached to an
elif statement (if any).
This enables us to write code of the form:
if command ran successfully
then
normal processing
else
error processing
fi
More specifically, we can now improve on the pushd
function that we saw in the last chapter:
pushd ( )
{
dirname=$1
DIR_STACK="$dirname ${DIR_STACK:-$PWD' '}"
cd ${dirname:?"missing directory name."}
echo $DIR_STACK
}
This function requires a valid directory as its argument.
Let's look at how it handles error conditions: if no
argument is given, the third line of code prints an error
message and exits. This is fine.
However, the function reacts deceptively when an
argument is given that isn't a valid directory. In case you
didn't figure it out when reading the last chapter, here is
what happens: the cd fails, leaving you in the same
317
Related documents
Learning the bash Shell, 3rd Edition By Cameron
Stegasaurus: A Simple Image Steganography Program
Migration guide - FTP Directory Listing
Duchess User Guide
chapter 5 using your protector demonstration hood
StampManage 2014 Getting Started Guide
PDF of first part
Bayesian Analysis for Stellar Evolution with Nine Parameters
Performers Go Web
The IDT79R3071™, IDT 79R3081™ RISController™ Hardware
EXHIBITOR REGULATIONS
Block 1 User`s Manual.book
Digital Acoustics EDB-110 Hardware manual