- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}
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
тАО08-01-2009 05:54 PM
тАО08-01-2009 05:54 PM
$ uname -a
HP-UX HostnameWithheld B.11.11 U 9000/800 2976059455 unlimited-user license
$ cat TEST
#!/bin/sh
up(){tr 'a-z' 'A-Z'}
echo "test" | up
$ ./TEST
Bus error(coredump)
Fixing just *one* of the two syntax problems (insert space after '{', or either ';' or line change before '}') yields the expected behavior (sh complains about the remaining other syntax error).
Kind regards,
J. Bern
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2009 09:20 AM
тАО08-02-2009 09:20 AM
Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}
#!/bin/sh
function up {
tr 'a-z' 'A-Z'
}
echo "test" | up
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2009 09:48 AM
тАО08-02-2009 09:48 AM
Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}
I can reproduce the behavior you describe on an 11.23 Itanium server too. As you noted, "
Fixing just *one* of the two syntax problems (insert space after '{', or either ';' or line change before '}') yields the expected behavior (sh complains about the remaining other syntax error)."
#!/usr/bin/sh
up(){ tr 'a-z' 'A-Z'; }
echo "test" | up
...works [although that's not a style I would use even for a one-line subroutine].
Interestingly, while what you show gives a bus-error with the Posix shell, under the Korn shell (ksh88) an informative syntax error occurs:
# cat ./TEST
#!/usr/bin/ksh
up(){tr 'a-z' 'A-Z'}
echo "test" | up
#./TEST
up: {tr: not found
...and using the Korn93 shell:
# cat ./TEST
#!/usr/dt/bin/dtksh
up(){tr 'a-z' 'A-Z'}
echo "test" | up
# ./TEST
./TEST: line 2: {tr a-z A-Z}: not found
So it would seem that the Posix shell needs a bit of self-preserving repair.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2009 04:46 AM
тАО08-03-2009 04:46 AM
Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}
#!/bin/sh
function up {
tr "[:lower:]" "[:upper:]"
}
echo "test" | up
Because of deficiencies in the POSIX standard, there are two types of functions and they are not exactly equivalent.
The first is: function_name(){function_body}
In this form, the function does not provide scoping of variables or traps and makes it easy to write functions with unexpected side effects. Fot this reason, this form should not be used (deprecated).
The second (and preferred) method is: function function_name {function_body}
This form overcomes the limitations of the first form.
Finally, tr has explicit character classes: alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, or xdigit. I much prefer explicit definitions rather than 'a-z' 'A-Z' as the purpose of the translation is readily apparent.
This is where a scripting style that is easy to understand (and portable) is more important than just getting something to work.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2009 08:04 AM
тАО08-03-2009 08:04 AM
Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}
What I need help with is passing the information to HP that there's something in HP-UX - namely, sh-posix *dumping core* on this example script instead of reporting a syntax error - that they might want to fix in future releases. As I said, I don't have direct access to my client's HP-UX support, and there doesn't seem to be a bug report address / web form I can find.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2009 12:22 AM
тАО08-07-2009 12:22 AM
SolutionYou have to have a support contract to contact the Response Center to file bugs.
I filed QXCR1000955649 for you:
Signal 10 in sh on illegal function syntax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2009 01:58 AM
тАО08-07-2009 01:58 AM
Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}
Cool, thanks!
[Off to update client's ticket system so as to avoid double reporting]