TimCS.Co.Uk Linux Linux Useful Information Linux scripting hints and tips
Linux scripting hints and tips


Q. How do I create a file with the current date as its name

A. First type : now=`date +%d%m%y' and then use this as the filename by referring to it in the code as $now. So if it needed to be displayed to screen echo $now would work.

Or if zipping up a file either zip $now or pkzip $now . Basically now is a variable and can be then used like any Linux/Unix variable by referring to it with a $ infront of the name.

Q. I would like to create a menu for users to choose options.

A. To do this use the follow code as and example:
option=1

while [ $option != 0 ]; do
clear
echo
echo Enter an Option from the Menu
echo
echo 1 This is option number 1
echo 2 This is option number 2
echo  -------------------------------
echo 0 Exit Menu
echo --------------------------------
read option catch

if [ $option = 1 ]; then
clear
echo you have chosen option number 1
read
fi

if [ $option = 1 ]; then
clear
echo you have chosen option number 2
read
fi
done
exit 0


This code shows that choosing either option 1 or 2 will display a message and wait for a key press which will go back to the menu. If 0 is entered then the menu ends.
 

Powered by Joomla!. Valid XHTML and CSS. Credits go to Gareth Flowers for his help with this site.