Function Problem and CoreDump

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Function Problem and CoreDump
# 8  
Old 02-19-2008
I did not know you could legally change shell inside a function... I will have to try it.
# 9  
Old 02-19-2008
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 ======
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.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with (Understanding) function

I have this code #!/bin/bash LZ () { RETVAL="\n$(date +%Y-%m-%d_%H-%M-%S) --- " return RETVAL } echo -e $LZ"Test" sleep 3 echo -e $LZ"Test" which I want to use to make logentrys on my NAS. I expect of this code that there would be output like 2017-03-07_11-00-00 --- Test (4 Replies)
Discussion started by: matrois
4 Replies

2. Shell Programming and Scripting

Coredump when passing file name to ksh function

Hi, I'm playing with ksh. I'm trying to do a simple task: read file name from cli and call a function which calculated number of lines in file. I'm getting coredump every time when I try to read that file. Korn shell version $ print ${.sh.version} Version AJM 93u+ 2012-08-01 Main... (5 Replies)
Discussion started by: solaris_user
5 Replies

3. Shell Programming and Scripting

Function problem

hey guys, im trying to learn bourne shell atm and I'm having some issues with functions. so heres my code: #!/bin/bash ##functions memory () { free -m } space () { df -h } ip () { (5 Replies)
Discussion started by: hawkfro12
5 Replies

4. Shell Programming and Scripting

Calling Function Problem

Hi, I had a scripts which calls two function. One function will call another function, script is working fine but the second function is not calling the first function. Below is the script #!/usr/bin/ksh fun1() { echo $DATETIME >> Test1.ksh return 0 } fun2() { typeset DATETIME=`date... (5 Replies)
Discussion started by: somu_june
5 Replies

5. Shell Programming and Scripting

splice function problem

Hi All, I am using splice function in for loop to delete particular element from array with one condition. my $cnt=0; foreach my $elem (@result) { if (condition){ splice(@result, $cnt, 1);} else{ $cnt++;} } Now when in array, two elements comes sequentially with the... (3 Replies)
Discussion started by: gentleDean
3 Replies

6. Shell Programming and Scripting

problem, with if condition in function

Hi All, I have a function which reads parameter and gets the value from config file. The entry in the file can be either of two Name=value or Name=value so if the variant is not present it should return me the generic value ie Name without variant. I am first searching for variant in... (4 Replies)
Discussion started by: gurukottur
4 Replies

7. Shell Programming and Scripting

Problem with function script.

Need an extra set of eyes. Can't find function. Can someone help, please. Thanks echo " Is this the correct list of tapes to eject (y/n)?" read option echo $option case $option in y|Y) TAPE_ROUTINE;; ... (3 Replies)
Discussion started by: gzs553
3 Replies

8. Shell Programming and Scripting

Problem with Recursive function

Hi all, I have to move all the files in a tree directory structure to a single directory. Inorder to know which file is from which directory , i'll have to add the name of the directory to the file name. For this i wrote a recursive function which is as follows... (4 Replies)
Discussion started by: malle
4 Replies

9. Shell Programming and Scripting

PERL function problem

I have perl script as follow. ------------------------------------------------------------------------ #! /usr/bin/env perl use strict; sub printLines { print "Inside the function.............\n"; my (@file , $count , $key ) = $_; print $count , $ key ; #... (2 Replies)
Discussion started by: avadhani
2 Replies

10. Programming

rexec() function problem

Hi folks, I'm trying to make a reconnection algorithm using rexec(), but I noticed that when rexec() fails returning -1, it is impossible to make it run successfully again until you restart the program or the thread. Example, I have a endless loop for connection retries, if I supply a wrong... (7 Replies)
Discussion started by: lcmoreno
7 Replies
Login or Register to Ask a Question