- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- Abnormal if condition behavior in script.
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- Report Inappropriate Content
03-09-2004 01:31 AM
03-09-2004 01:31 AM
Abnormal if condition behavior in script.
I input the attached file to the following script.
+++++++++++++++++++++++++++++++++++++++++++++
#!/bin/bash
num="`awk '/X-MailRelay-ToCount/{print $2}' $1`"
echo $num
if test "${num}" = "1"
then
echo num eq to 1
else
echo num not eq to 1
fi
exit
++++++++++++++++++++++++++++++++++++++++++++
But when I execute the script it doesn't not output the desired output.
Means when $num =1, it should output "num eq to 1" ,BUT it outputs the else part.
Please help me to resolve this abnormal behavior.Any modifications to the script.
Big thank.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-09-2004 01:46 AM
03-09-2004 01:46 AM
Re: Abnormal if condition behavior in script.
in this line:
if test "${num}" = "1"
I mean you want to say if it's equal then do something.
In your script it says it's equal .
Not that I'm great with bash scripts...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-09-2004 02:47 AM
03-09-2004 02:47 AM
Re: Abnormal if condition behavior in script.
He has your error :)
P.S. No points for this one please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-09-2004 06:38 AM
03-09-2004 06:38 AM
Re: Abnormal if condition behavior in script.
you use == for string comparison.
you use -eq for integer comparison.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-09-2004 07:12 AM
03-09-2004 07:12 AM
Re: Abnormal if condition behavior in script.
if [ ${num} -eq 1 ]; then
.....
penguin
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP