Well, I am currently a novice shell scripter. I have a basic knowledge of other programming languages such as Javascript for HTML, JScript, VB.NET, and C++. (C++ Not so much, just dipped my feet in the water for that). Most recently, my recent project has been attempting to learn as much as I can about Bash shell scripting. The current issue is understanding status error codes, as well as checking if certain parameters contain directories or if it exists at all. I am working from a book, with tutorials and review questions. Unfortunately there is no answer key, or even hints for that matter.
- Display an error message and exit with status 1 if no parameters are given
- Display an error message and exit with status 2 if source is not a directory
- Display an error message and exit with status 3 if destination does not exist or is not a directory
The above is what I must do, so far the first one I believe I have done correctly, if not please, correct me, or guide me in the proper direction. As I learn best when samples are given, I thought I would ask for assistance.
if [ $? ]; then
echo "You must supply at least one parameter"
exit 1
fi
#The above is the part I am pretty sure is correct.
if [ $? -d $directory "$1" ]; then
echo "$directory is not a directory"
exit 2
fi
#The above was self written. I am almost positive it is wrong.
if [ $? -lt 2 ]; then
set "$1" .pwd
fi
#the above was given to me from the book as a reference point to start (tutorial)