- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Variable comparison
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
тАО04-14-2004 08:14 PM
тАО04-14-2004 08:14 PM
In my script I have 2 variables which I want to compare against one another.
a="printer01-01 Apr 10:05"
b="printer01-01 Apr 10:05"
What should the synthax be when i wanna equate whether these 2 are equal to each other?
Should it be $a == $b or wat? Please advise. Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2004 08:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2004 08:32 PM
тАО04-14-2004 08:32 PM
Re: Variable comparison
I have tried as per suggested. But I'm still facing problem. When I tried the first suggestion,
if ["$a"=="$b"]
then
echo equal
else
echo unequal
fi
I got this error:
./test.sh[4]: [printer01-01 Apr 10:05==printer01-01 Apr 10:05]: not found.
Am I doing it correctly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2004 08:43 PM
тАО04-14-2004 08:43 PM
Re: Variable comparison
there must be s space to separate the brackets from the stuff within.
[ "$a" == "$b" ]
hth,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2004 08:47 PM
тАО04-14-2004 08:47 PM
Re: Variable comparison
The right command line is:
if [ "$a" = "$b" ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2004 08:53 PM
тАО04-14-2004 08:53 PM
Re: Variable comparison
a="printer01-01 Apr 10:05"
b="printer01-01 Apr 10:05"
c="printer01-02 Apr 10:05"
if test "$a" = "$b"
then
echo "equal"
else
echo "unequal"
fi
if [ "$a" = "$c" ]
then
echo "equal"
else
echo "unequal"
fi
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2004 08:54 PM
тАО04-14-2004 08:54 PM
Re: Variable comparison
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2004 08:56 PM
тАО04-14-2004 08:56 PM
Re: Variable comparison
if [ "$a" = "$b" ]
then
echo blabla
fi
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2004 02:08 AM
тАО04-15-2004 02:08 AM
Re: Variable comparison
It ('==') behaved well on my Linux / bash. I'll have to check it (for myself). To be honest, I normally use one '=', but all these language differences...
The space it there. It's funny: when I type my answers I have a mono-spaced font, and the spaces are clearly visible. But after posting the reply, the font is variable width and spaces are difficult to see.
That's why you should use Copy/Paste.
Sorry for the confusion.
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2004 05:44 PM
тАО04-15-2004 05:44 PM
Re: Variable comparison
the better way to compare this if u r using kshell is
if [ "${a}" = "${b} ]
then
echo ${a} and ${b} are equal
else
echo ${a} and ${b} are not equal
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2004 06:29 PM
тАО04-15-2004 06:29 PM
Re: Variable comparison
if
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2004 09:21 PM
тАО04-15-2004 09:21 PM
Re: Variable comparison
[ "$a" -eq "$b" ]
to avoid the space or no space confusion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2004 09:33 PM
тАО04-15-2004 09:33 PM
Re: Variable comparison
JP.
P.S. I think this thread could be considered closed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2004 01:15 PM
тАО04-18-2004 01:15 PM
Re: Variable comparison
Finally I'm able to test out my scripts now.
Regards
Khian Wei
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2004 05:23 PM
тАО04-18-2004 05:23 PM