- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Abnormal if condition behavior in script.
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
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
тАО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
- 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
- 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
- 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
- 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