Trying to make a script that will clear the screen, present the user with some enumerated choices, warn them if an invalid option is entered, and keep on cycling until they break it off.
Evaluate the arguments and terminate the script (with an appropriate message) if invalid or incomplete options are entered.
Option 1 Presents the current date in International Format :
i.e. today would be 22-MAR-2010 (note the dashes and caps).
Option 2 Show the contents of a user specified file if it exists; otherwise complain.
Option 3 Compile a specified c++ program. The program will be compile a c++ program is g++ [program name]. It will produce a file called a.out. Redirect any errors. Build an executable
If the compilation is successful, rename the a.out to the name of the source file followed by .exe. Get a confirmation by the user if you are replacing an existing file.
Option 0 terminate the script.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Had tried a bash script and got some errors and here it is
errors i got : options.shl: line 5: declare: -l: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
options.shl: line 55: syntax error near unexpected token `in'
options.shl: line 55: `as || in php; #this is the "no" part'
#!/bin/bash
ACTION=$1
#ACTION="TiMe"
declare -l ACTION # -l means lowercase
ACTION=$ACTION
WHEN=$2
ACTION_LIST="[Q]uit - [t]ime - [s]how"
echo $ACTION
if [ -z $ACTION ]; then
echo "You need to specify action"
echo "Action list: "
echo "$ACTION_LIST"
echo -n "Enter choice: " # -n means do not display the last line after (it's turned on by default)
read choice_action
if [ -z $choice_action ]; then
ACTION="quit"
else
ACTION=$choice_action
fi
fi
echo "PRE $ACTION POST"
if [ $ACTION = "time" -o $ACTION = "t" ]; then #you specify commands or "Actions" like this
DATE=`date +%d`
MONTH_ABV=`date +%b`
YEAR=`date +%Y`
MONTH_ABV_CAPS="$(echo "${MONTH_ABV}"|tr 'a-z' 'A-Z')"
echo "$DATE-$MONTH_ABV_CAPS-$YEAR"
elif [ $ACTION = "quit" -o $ACTION = "q" ]; then #you specify commands or "Actions" like this
echo "Exiting..."
exit
elif [ $ACTION = "file" -o $ACTION = "show" -o $ACTION = "f" -o $ACTION = "s" ]; then #you specify commands or "Actions" like this
ACTION_ALIAS_LONG="show file"
ACTION_ALIAS_SHORT="s"
if [ -z $WHEN ]; then # -z means does not exist
echo -e "You did not specify what to $ACTION_ALIAS_LONG\nPlease specify an option" #-e means enable backslash commands
echo "Possible choices: [Q]uit - X (Will $ACTION_ALIAS_LONG on the targeted file (X))"
echo -n "Enter choice: " # -n means do not display the last line after (it's turned on by default)
read choice
declare -l choice #-l means lowercase
choice=$choice
if [ -z $choice ]; then #-z mean does not exist
echo "You did not enter anything, assuming quit"
#do nothing
elif [ $choice = "quit" -o $choice = "q" ]; then

means or, also known as || in php; #this is the "no" part
echo "You entered quit, exiting"
else
WHEN=$choice
WHAT=$WHEN
cat $WHAT #cat already has a error message - Hurray!
fi
else
WHEN=$choice
WHAT=$WHEN
cat $WHAT #cat already has a error message - Hurray!
fi
else
echo "Command not found."
echo "Try again"
exit
fi
