Operating System - HP-UX
1752273 Members
4737 Online
108786 Solutions
New Discussion юеВ

sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

 
SOLVED
Go to solution
Jochen Bern
New Member

sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

Hello everyone, I chanced onto this while working on a client's HP-UX installation (read: no support contract available to me directly). There's a report in the client's trouble ticket system, but I have no idea how long it'll need to percolate to anywhere HP can see it, so I'd like to toss the info out here as well:

$ 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
6 REPLIES 6
Mel Burslan
Honored Contributor

Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

I for one do not know the internals of POSIX but one thing I learned in my hpux sysadmin life, it is very finicky about function declarations. This below works for me but combining the word function on the same line as the tr and curly brackets throws a hissy fit for some reason. I hope this works for you:

#!/bin/sh
function up {
tr 'a-z' 'A-Z'
}
echo "test" | up
________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

Hi Jochem:

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...
Bill Hassell
Honored Contributor

Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

I would agree that the style of this code is quite obtuse, something that leads to non-portability and long hours trying to figure out why something is not working. I would definitely recode this to a working style (POSIX, ksh, bash, etc) like this:

#!/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
Jochen Bern
New Member

Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

I'm sorry, I didn't make quite clear what I'm looking for. I do know how to get the script to work, and I did *not* hose the machine in question (as in, "this looks helpful, let's toss it into /etc/profile so that everyone can use it" ;-).

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.
Dennis Handly
Acclaimed Contributor
Solution

Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

>there doesn't seem to be a bug report address / web form I can find.

You 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
Jochen Bern
New Member

Re: sh-posix dumps core on: up(){tr 'a-z' 'A-Z'}

> I filed QXCR1000955649 for you

Cool, thanks!

[Off to update client's ticket system so as to avoid double reporting]