- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Korn Shell String Comparison problem
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
11-02-2003 06:02 PM
11-02-2003 06:02 PM
Korn Shell String Comparison problem
mddv02@/apps/bin>getconf KERNEL_BITS
64
The following script give the expected result:
#!/usr/bin/ksh
this_file_date=12345678901234
last_file_date=02345678901234
if [ $this_file_date -gt $last_file_date ]; then
# echo $raw_file_name >> $FTP_LIST
echo "select:" $this_file_date
fi
mddv02@/apps/bin>ksh test2_string.ksh
select: 12345678901234
The Next one doesn't give us the correct result
mddv02@/apps/bin>cat test2_string_no.ksh
#!/usr/bin/ksh
this_file_date=123456789012345
last_file_date=023456789012345
if [ $this_file_date -gt $last_file_date ]; then
# echo $raw_file_name >> $FTP_LIST
echo "select:" $this_file_date
fi
mddv02@/apps/mdsamd/mdsamd/arc/bin>ksh test2_string_no.ksh
mddv02@/apps/mdsamd/mdsamd/arc/bin>
So the problem if the value of the string is more than 14 characters it can not compare correctly (the second script is the one with more than 14 characters). Is it a bug? if it's a bug, any fix? Or is this the limitation of the HPUX?
(BTW those 2 scripts can run in Tru64 Unix without problem)
Thank You,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 06:15 PM
11-02-2003 06:15 PM
Re: Korn Shell String Comparison problem
1972608889 respectively. My guess is that True64 has a longer long.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 06:30 PM
11-02-2003 06:30 PM
Re: Korn Shell String Comparison problem
You can get around the problem like this
#!/usr/bin/ksh
this_file_date=123456789012345
last_file_date=023456789012345
(( result = $this_file_date - $last_file_date ))
if [ $result -gt 0 ]; then
# echo $raw_file_name >> $FTP_LIST
echo "select:" $this_file_date
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 07:52 PM
11-02-2003 07:52 PM
Re: Korn Shell String Comparison problem
I suggest to use 'bc' command to handle large integers:
echo "if ($this_file_date>$last_file_date) a=a+1; a" | bc | read OUTCOME
if [[ "$OUTCOME" -eq 1 ]]
then
.
.
.
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 08:21 PM
11-02-2003 08:21 PM
Re: Korn Shell String Comparison problem
One of the suggestions above may not give the results you expect. ie.
# this_file_date=123456789012345
# last_file_date=023456789012345
# (( result = $this_file_date - $last_file_date ))
# echo $result
276447232
whereas if you use bc:
# bc
123456789012345-023456789012345
100000000000000
There have been previous neat solutions where bc is used as a co-process from a shell.
Something like
# bc |&
# print -p $this_file_date -$last_file_date
# read -p answer
# if [ $answer -gt 0 ] ;then etc...;fi
# print -p quit
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 08:32 PM
11-02-2003 08:32 PM
Re: Korn Shell String Comparison problem
I realised whilst out having a quick smoke that the workaround I posted earlier is really not a good idea and if it works, it works for the wrong reasons.
I'd do it in perl :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 09:07 PM
11-02-2003 09:07 PM
Re: Korn Shell String Comparison problem
Thanks alot for the very quick answer. I think the problem is more like what Mark Grant said. is about the diff. between how long the integer value in HPUX and Tru64.
Then another question pop up. Anyone know how long the integer in HP/UX Korn Shell? Can we use longer integer value?
The problem I can not just change the script, is by the Application Vendor. But if it's the way HPUX integer should be, I can ask the Apps Vendor to change, as long as it is not a bug.
Thank again,
Iwan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 09:17 PM
11-02-2003 09:17 PM
Re: Korn Shell String Comparison problem
Here's what I get on my hp-ux system.
getconf INT_MAX
2147483647
getconf KERNEL_BITS
64
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2003 10:29 PM
11-02-2003 10:29 PM
Re: Korn Shell String Comparison problem
I suspect you need to start talking to your vendor!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2003 08:13 PM
11-03-2003 08:13 PM
Re: Korn Shell String Comparison problem
This is not a HP-UX problem, but a ksh problem.
Try to compare the strings instead:
if [[ $string1 > $string2 ]]
then
do_something
fi