Testing For File Charactereristics

commandline session

$cat test.sh
#!/usr/bin/env bash
# cookbook filename: checkfile
#
DIRPLACE=/tmp
INFILE=/home/jeffrin/amazing.data
OUTFILE=/home/jeffrin/more.results
if [ -d "$DIRPLACE" ]
then
cd $DIRPLACE
if [ -e "$INFILE" ]
then
if [ -w "$OUTFILE" ]
then
doscience > "$OUTFILE"
else
echo "can not write to $OUTFILE"
fi
else
echo "can not read from $INFILE"
fi
else
echo "can not cd into $DIRPLACE"
fi

$sh test.sh
can not read from /home/jeffrin/amazing.data
$> /home/jeffrin/amazing.data
$sh test.sh
can not write to /home/jeffrin/more.results
$> /home/jeffrin/more.results
$sh test.sh
test.sh: 14: test.sh: doscience: not found
$

related source : Bash CookBook

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 )

Google photo

You are commenting using your Google 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