- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- If Then Else Statement Help
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
Discussions
Discussions
Discussions
Forums
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
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
тАО11-08-2001 09:45 AM
тАО11-08-2001 09:45 AM
Here is an example one value that works.
******************************
NAME=$1
if [ $NAME = "John" ] ; then
echo $NAME
else
exit 0
fi
****************************
What i need to do is add another possible value in the if statement where $NAME could equal "John or "Jane".
I can't seem to get the syntax correct.
Thanks
Jeff
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 09:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 09:56 AM
тАО11-08-2001 09:56 AM
Re: If Then Else Statement Help
export NAME=$1
if [ $NAME = "John" ] ; then
echo "John $NAME "
elif [ $NAME = "Jane" ] ; then
echo "Jane: $NAME"
exit 0
fi
(man ksh / look for case if there is multiple options)
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 09:56 AM
тАО11-08-2001 09:56 AM
Re: If Then Else Statement Help
Thanks
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 09:56 AM
тАО11-08-2001 09:56 AM
Re: If Then Else Statement Help
Try
if [ "$NAME" = "John" || "$NAME" = "Jane"] ; then
echo $NAME
else
exit 0
fi
I think && is the AND....
Note that the /sbin/init.d directory has loads of HP startup scripts that are a good start to look for syntax :-)
Cheers,
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 09:58 AM
тАО11-08-2001 09:58 AM
Re: If Then Else Statement Help
if [ "${name}" = "John" -o "${name}" = "Jane" ]
then
echo "Ok"
else
echo "Bad"
fi
Note the quotes around "${name}" - they protect you in case the variable is ever null;
Here's a variant with numeric comparisons using and
if [ ${a} -ge 1 -a ${a} -le 10 ]
then
echo "${a} is in range"
else
echo "${a} is out of range"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 09:59 AM
тАО11-08-2001 09:59 AM
Re: If Then Else Statement Help
use -o option for giving the OR choice.
[ $NAME = "John" -o $NAME = "Jane" ]
everything else remaining the same.
(you can do a man on ksh for other related
options)
-raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 10:02 AM
тАО11-08-2001 10:02 AM
Re: If Then Else Statement Help
[[ $NAME = John || $NAME = Jane ]] && echo $NAME || exit
A one-liner without the "if" and the "then"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 10:04 AM
тАО11-08-2001 10:04 AM
Re: If Then Else Statement Help
-o stands For OR ... -a => AND
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-08-2001 10:06 AM
тАО11-08-2001 10:06 AM
Re: If Then Else Statement Help
The '-o' is "or". '-a' denotes "and". Have a look at the man pages for 'test' ('man test').
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2004 12:53 AM
тАО04-23-2004 12:53 AM
Re: If Then Else Statement Help
good advice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2004 01:12 AM
тАО04-23-2004 01:12 AM
Re: If Then Else Statement Help
kaps