I'm creating a junk script which utilizes either -l or -p to list files or remove files, respectively, in the junk directory. When I run this code, inputting '-p' is unrecognized through the whole if/else block and falls to the last else (echo do nothing). In addition, I switched tests and tested for '-p' first, seeing if I could uncover hints, and inputting '-l' still made it catch on that first test even though it was testing for '-p'! (with input of -p still falling through.)
So confused. I've tried different quoting schemes, but maybe not the right one.
#! /usr/bin/sh
if [ ! -n "$1" ]
then
echo "Usage: junk -l | -p | {filename}*"
else
if [ "$1" -eq "-l" ] # Test for '-l' input. Will always stop here, even if testing for '-p'
then
echo "The -l option was given"
echo "The contents of the directory will be listed"
else
if [ "$1" -eq "-p" ] # Test for '-p' input
then
echo "The -p option was given"
echo "Directory and all files will be removed"
else
echo "do nothing" # '-p' always fall through to here.
fi
fi
fi
exit 0