Function Problem and CoreDump

Hi, i have a question:

i build this function:

function WriteLog {

....
...
print $*
print $* >> FileLog

....
....
}

the function are called with this sintax:

.....
.....

WriteLog "XXXXXXXX"

......

this operation work correctly.

but when call the function with this sintax:

WriteLog $A$B

or

WriteLog "\tXXXXXX \tXXXXXX \c"

or

WriteLog $A${B[XX]}

or
WriteLog "XXXXXX"" ""BBBBBBB"

I have error "COREDUMP"

but if assign a variable the string : for ex StringaExe="X\tBBBBBB\t\tCCCC"

and call WriteLog $StringExe

I have not problem !!!!

I Things $* it's correctly assign when call the function ????

try:

function WriteLog {
print "$1"
print "$1" >> FileLog
}

# call it with " around the arguments, example:
WriteLog "$A${B[XX]}"

not work ..

I have the same error

the call WriteLog ""\tCAMPA\t\t CAMPB\tCAMPC""

or WriteLog "\tCAMPA\t\t CAMPB\tCAMPC"
return e error

if write BBB="\tCAMPA\t\t CAMPB\tCAMPC"

and call WriteLog $BBB

work correctly

okay.

What shell are you using, what unix system? Most shells do not dump core in my experience.

ksh93 in Hp/ux system

Got it - ksh93 is an "add-on" not part of the HPUX standard distribution, AFAIK. For our HPUX boxes we get support only on sh and ksh. YMMV.

I believe you have a shell problem. The examples I gave you and the examples you gave me that failed are POSIX compliant and should work in a POSIX shell. I don't know how you'd get support from HP -- which is where I would start in another circumstance.

If you cannot get support, try /usr/bin/ksh Your examples should never coredump.

i have insert in the fuction the declare :

#!/usr/bin/sh or /usr/bin/ksh

function WriteLog {

#!/usr/bin/sh

.....
.....
.....

return
}

the shell work correctly and i use in the rest ksh93 !!!!

I don't Know because the sintax ksh93 in the function don't work !!!!

tanks

I did not know you could legally change shell inside a function... I will have to try it.

The first thing i notice is a problematic usage of the "print"-statement. The reason is, that "print" awaits one or more parameters and is satisfied with getting one. That may - depending on the variables contents - lead to unexpected results, like in this example:

function write_log
{
     print $*
}

# ======= first example ======
a="hello there"
b="; exit"

write_log $a $b

# ====== second example ======
a="-u2"
b="hi there"

write_log $a $b

In the first example the script will terminate because the expanded line reads "print hello there ; exit" and "exit" is a shell command. In the second example "-u2" is interpreted as an option to print instead of printable text. Maybe something along these lines has happened and is responsible for the coredump?

btw. the solution to the print-command being a bit ambigous is:

print - "$*"

After the dash everything is considered to be printable text and the double quotes around the variable take care that only one parameter is given to print.

I hope this helps.

bakunin