Previous in Forum: Biolux NG Microscope Driver   Next in Forum: Linux and Unix
Close
Close
Close
3 comments
Rating: Comments: Nested
Member

Join Date: Feb 2013
Posts: 8

Basic Shell / Bash Programming Linux / Unix

03/15/2013 4:31 PM

echo "what month..." read month echo "what year..." read yearif test " $month = [1-12] "
then cal "$month" "$year"
echo "you are now being redirected to the menu"
bash program.sh else echo " you entered a wrong number for month" exit 0
fi



So Im trying to write a command that shows a specific month and year you typed for the selections you enter but I can't figured to prevent the error cal month 13 is not a month...

Here's what is supposed to do....You typed a number for a month you are looking for, example january 1,february 2you typed a number for the year you are looking for ,example year 2012,2013 but I want to prevent that if the user types for instance month 13which is non existance to return him to the main menu which will run the script again..

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru

Join Date: Jan 2007
Location: Edinburgh, Bonnie Scotland
Posts: 1334
Good Answers: 23
#1

Re: Basic Shell / Bash Programming Linux / Unix

03/16/2013 4:21 AM

Read about data validation.

You require a line to redirect back to the start if the entered value is outwith the selection available. Also, let the user know what format to enter, so they do not attempt text.

__________________
Madness is all in the mind
Register to Reply
Guru

Join Date: Feb 2012
Posts: 595
#2

Re: Basic Shell / Bash Programming Linux / Unix

03/16/2013 6:52 AM

[?maybe]

echo "what month..." read month
echo "what year..." read year
if test " $month = [1-12] " <- (* http://www.linuxquestions.org/questions/programming-9/%5Bbash%5D-if-clause-718161/)
then cal "$month" "$year"
echo "you are now being redirected to the menu"
bash program.sh
else echo " you entered a wrong number for month" exit 0
fi

(from http://www.bing.com/search?q=linux+bash+batch+if+clause)
http://linuxconfig.org/Bash_scripting_Tutorial#9-bash-if--else--fi-statements
http://linuxconfig.org/Bash_scripting_Tutorial#10-bash-comparisons

if [ $NUM1 -eq $NUM2 ];

(*)

__________________
ci139
Register to Reply
Guru

Join Date: Apr 2010
Location: About 4000 miles from the center of the earth (+/-100 mi)
Posts: 9910
Good Answers: 1141
#3

Re: Basic Shell / Bash Programming Linux / Unix

03/16/2013 1:24 PM

I think "yearif" is run together. The if is the start of an if loop that ends in "fi". Put a return after "year"

Register to Reply
Register to Reply 3 comments
Copy to Clipboard

Users who posted comments:

ci139 (1); GM1964 (1); Rixter (1)

Previous in Forum: Biolux NG Microscope Driver   Next in Forum: Linux and Unix

Advertisement