- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: expr stripping off leading zeroes from a strin...
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
тАО02-05-2009 01:27 PM
тАО02-05-2009 01:27 PM
#!/bin/sh
x='00545'
expr substr "$x" 1 2
The above code produces the following output:
54
Shouldn't it have produced:
00
Running HP-UX 11.23 on Itanium servers.
Solved! Go to Solution.
- Tags:
- expr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 01:35 PM
тАО02-05-2009 01:35 PM
Re: expr stripping off leading zeroes from a string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 01:41 PM
тАО02-05-2009 01:41 PM
Re: expr stripping off leading zeroes from a string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 02:37 PM
тАО02-05-2009 02:37 PM
Re: expr stripping off leading zeroes from a string
This returns "00" on an 11.23 Itanium for me:
# cat ./mysh
#!/bin/sh
x='00545'
expr substr "$x" 1 2
# ./mysh
00
# what /bin/sh
/bin/sh:
Version M-11/16/88f
$ B.11.23 Aug 22 2007 09:08:12 $
builtin.c $Date: 2005/01/19 00:36:04 $Revision: r11.23/5 PATCH_11.23 (PHCO_32444)
service.c $Date: 2007/03/06 17:54:39 $Revision: r11.23/3 PATCH_11.23 (PHCO_34129)
xec.c $Date: 2005/11/22 04:08:50 $Revision: r11.23/6 PATCH_11.23 (PHCO_34129)
emacs.c $Date: 2007/01/05 12:12:17 $Revision: r11.23/4 PATCH_11.23 (PHCO_34129)
fault.c $Date: 2007/03/06 17:54:43 $Revision: r11.23/6 PATCH_11.23 (PHCO_34129)
history.c $Date: 2007/04/23 15:02:12 $Revision: r11.23/1 PATCH_11.23 (PHCO_36506)
io.c $Date: 2007/04/23 15:02:21 $Revision: r11.23/4 PATCH_11.23 (PHCO_36506)
jobs.c $Date: 2005/08/10 00:06:06 $Revision: r11.23/5 PATCH_11.23 (PHCO_32444)
test.c $Date: 2007/10/12 18:33:56 $Revision: r11.23/2 PATCH_11.23 (PHCO_36506)
$Revision: @(#) ksh R11.23_BL2007_1114_1 PATCH_11.23 PHCO_36506
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 02:49 PM
тАО02-05-2009 02:49 PM
Re: expr stripping off leading zeroes from a string
This seems to occur when we have UNIX95=XP64 in the environment. When we unset this, it works correctly. Now I'm wondering why it doesn't work when UNIX95=XP64.
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 03:01 PM
тАО02-05-2009 03:01 PM
Re: expr stripping off leading zeroes from a string
Using 11.23 (with current patches) on an rx2660, I can't reproduce this:
# cat ./mysh
#!/bin/sh
UNIX95=XP64
x='00545'
expr substr "$x" 1 2
...which works the same as :
# cat ./mysh
#!/bin/sh
UNIX95=
x='00545'
expr substr "$x" 1 2
...
I would never capriciously set 'UNIX95' unless you are specifically needing it; e.g with 'ps' to enable the '-o' formatting options.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 03:05 PM
тАО02-05-2009 03:05 PM
Re: expr stripping off leading zeroes from a string
>This seems to occur when we have UNIX95=XP64 in the environment. When we unset this, it works correctly. Now I'm wondering why it doesn't work when UNIX95=XP64.
You shouldn't be exporting UNIX95=MAKE_EXPR_HAVE_DIFFERENT_SUBSTR_RESULTS.
The POSIX standard says using substr on numbers is unpredictable.
The only time you should use UNIX95 is with:
UNIX95=EXTENDED_PS ps -Hef ...
This only exports UNIX95 for the one command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 03:09 PM
тАО02-05-2009 03:09 PM
Re: expr stripping off leading zeroes from a string
Do you have PHCO_36506 ? If not, you might try applying it (no reboot is required) and then retest.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 03:27 PM
тАО02-05-2009 03:27 PM
Re: expr stripping off leading zeroes from a string
We were exporting UNIX95=XPG4
Time for glasses...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2009 03:33 PM
тАО02-05-2009 03:33 PM
Re: expr stripping off leading zeroes from a string
Why would a shell patch break the correct standard behavior of expr(1), to make it work like Paul wants?
>just noticed a typo, We were exporting UNIX95=XPG4
No, you were really exporting: :-)
UNIX95=MAKE_EXPR_HAVE_DIFFERENT_SUBSTR_RESULTS
>Time for glasses
Or cut & past. :-)