- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: if statement issues....
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 06:08 PM
02-26-2008 06:08 PM
-----------------------------------------------
echo "This is the max size your lvol can be:"
echo $MAXSIZE
echo
echo Do you want to max out the size of your lvol?
print -n "Enter 'y' for Yes or 'n' for No :"
read ANSWER3
if [ $ANSWER3="n" ] || [ $ANSWER3="N" ] || [ $ANSWER3="no" ] || [ $ANSWER3="No" ]
then
exit
else
continue
fi
if [ $ANSWER3="y" ] || [ $ANSWER3="Y" ] || [ $ANSWER3="yes" ] || [ $ANSWER3="Yes" ]
then
echo
echo "vxassist -g $DISKGROUP growto $LVOL $MAXSIZE"
vxassist -g $DISKGROUP growto $LVOL $MAXSIZE
exit
else
exit
fi
-----------------------------------------------
Solved! Go to Solution.
- Tags:
- expression
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 07:35 PM
02-26-2008 07:35 PM
SolutionI will try not to make any major changes in
your script, although your problem can be
rewritten in much better ways :)
A) There is no print statement in standard Shells.
b) Your "if" loops were wrong.
c) It is good to wrap $ANSWER3 in quotes so
if a user types nothing, you do not get an
error.
echo "This is the max size your lvol can be:"
echo $MAXSIZE
echo
echo Do you want to max out the size of your lvol?
#print -n "Enter 'y' for Yes or 'n' for No :"
echo -n "Enter 'y' for Yes or 'n' for No :"
read ANSWER3
if [ "$ANSWER3" = "n" -o "$ANSWER3" = "N" -o "$ANSWER3" = "no" -o $"ANSWER3" = "No" ]
then
exit
else
continue
fi
if [ "$ANSWER3" = "y" -o "$ANSWER3" = "Y" -o "$ANSWER3" = "yes" -o "$ANSWER3" = "Yes" ]
then
echo
echo "vxassist -g $DISKGROUP growto $LVOL $MAXSIZE"
vxassist -g $DISKGROUP growto $LVOL $MAXSIZE
exit
else
exit
fi
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 07:40 PM
02-26-2008 07:40 PM
Re: if statement issues....
Replace the first "if" statement with:
if [ "$ANSWER3" = "n" -o "$ANSWER3" = "N" -o "$ANSWER3" = "no" -o "$ANSWER3" = "No" ]
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 08:42 PM
02-26-2008 08:42 PM
Re: if statement issues....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 09:01 PM
02-26-2008 09:01 PM
Re: if statement issues....
You can eliminate having to test to lowercase and uppercase replies (or MiXeD caes!) by using 'typeset -l':
typeset -l ANSWER3
...now, whenever your perform:
read ANSWER3
...the variable will contain only lowercase characters.
Regards!
...JRF...
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 09:46 PM
02-26-2008 09:46 PM
Re: if statement issues....
case $ANSWER in
n|N|no|No|NO|NO!) exit ;;
y|Y|yes|Yes) ;; # fall thru
*) exit ;;
esac
>Dusan: A) There is no print statement in standard Shells.
Sure there is. :-) A real shell has it. In fact I've seen people that frown on using echo and want you to use print. But both are builtin in a real shell.
>b) Your "if" loops were wrong.
Yes. But if you still want to use ||:
if [[ "$ANSWER3" = "n" || "$ANSWER3" = "N" || "$ANSWER3" = "no" || "$ANSWER3" = "No" ]]
>c) It is good to wrap $ANSWER3 in quotes
I've seen pedantic cases where they go further to handle leading "-":
X"$ANSWER3" = X"n"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 01:34 AM
02-27-2008 01:34 AM
Re: if statement issues....
OK, now that things work, let's make
improvements.
With all nice inputs from others, we can
make it a bit simpler and more efficient.
a) You do not really need two "if"
statements. The small case-statement will
handle it safely.
b) Since standard HP-UX Shells are not Posix shells, "print" statement is still better
to be left out and "echo" used instead.
c) You can narrow down your input
to the first character only and then check
if it is "n" or "y".
echo "This is the max size your lvol can be:"
echo $MAXSIZE
echo
echo Do you want to max out the size of your lvol?
echo -n "Enter 'y' for Yes or 'n' for No :"
read ANS
if [ "$ANS" ]
then
ANSWER3="`echo $ANS |cut -c1`"
typeset ANSWER3
else
ANSWER3=""
fi
case $ANSWER3 in
n*|N*) exit
;;
y*|Y*) echo
echo "vxassist -g $DISKGROUP growto $LVOL $MAXSIZE"
vxassist -g $DISKGROUP growto $LVOL $MAXSIZE
;;
*) exit ;;
esac
exit 0
As you can see, many choices :)
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 01:45 AM - edited 09-17-2011 01:31 PM
02-27-2008 01:45 AM - edited 09-17-2011 01:31 PM
Re: if statement issues....
>Dusan: b) Since standard HP-UX Shells are not Posix shells, "print" statement is still better to be left out and "echo" used instead.
You are confused only on your first point. sh IS the Posix shell (a real shell).
http://h20000.www2.hp.com/bc/docs/support/SupportManual/c02267598/c02267598.pdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 07:46 AM
02-27-2008 07:46 AM
Re: if statement issues....
the linux types are pushing "dash" as *the* standard shell, and substituting c-style 'print' instead of 'echo'....
claim it "eliminates incompatibilities" between implementations of "echo"..
the def. shell in ubuntu is now dash, and you'd be amazed how many previously working installation scripts are now broken, at least temporarily
then they hit real unix....and wonder where all the non-std gnu options went
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 07:56 AM
02-27-2008 07:56 AM
Re: if statement issues....
...and while we are discussing favorite shells, remember NEVER change root's default shell from '/sbin/sh' to anything else!
The '/sbin/sh' is a statically-linked POSIX shell that does not need any libraries found in '/usr'. Thus, in single-user mode it is capable of doing everything it needs.
For most users, the POSIX shell which uses dynamically linked libraries is preferred. This is '/usr/bin/sh'. This improves the overall memory footprint somewhat, since multiple instantiations can share some code.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 04:34 PM
02-27-2008 04:34 PM
Re: if statement issues....
You'll find that if you get a bean counter to add up the numbers, it probably doesn't.
The size of a process is 1 X the text size. And N X the data size. You'll find that the N X D far out weighs the 1 X T vs 1 X T' savings for the shared version.
That said, you should still use /usr/bin/sh so you can use fancy smancy locales.
- Tags:
- locale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2008 07:41 AM
02-29-2008 07:41 AM
Re: if statement issues....
Actually, do your really need to test for both a 'y' and an 'n'? Aren't you really interested in only one answer, the 'y' one?
I have a small function I use any time I need this functionality. Here it it:
ask_yn() {
echo "Enter [y] to continue: \c"
read ans
if [ -z "$ans" -o "$ans" != "y" ] ; then
echo "Aborting"
exit
fi
}
In other words, I really don't care if the answer is anything other than 'y', becuase I'm bailing out if it's not.
Yes, you can do all the checks to see if it's cap, whole word, etc. but I'm just illustrating a point.
Regards,
Mark