need help with User Defined Function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help with User Defined Function
# 8  
Old 11-16-2007
Quote:
Originally Posted by porter
Um, then try "$1"_plt or $1"_plt"
Thanks but I am afraid it is also not working..

showing the below error
cat: cannot open /tmp/I_out.plt20546

Smilie
Now I am doing like this
Code:
I_plt=/tmp/I_out.plt$$
Q_plt=/tmp/Q_out.plt$$
 
plot(){
  echo "#!/usr/local/bin/gnuplot -persist" > /tmp/"$1"_out.plt$$
  echo "plot \"$1_indat.txt\" " >> /tmp/"$1"_out.plt$$
  
 }

  plot I
  cat $I_plt 
  plot Q
  cat $Q_plt

But I think there should be a better way to doing this ..

Thanks for your help..

Last edited by user_prady; 11-16-2007 at 01:22 AM..
# 9  
Old 11-16-2007
What shell are you using?
# 10  
Old 11-16-2007
Quote:
Originally Posted by porter
What shell are you using?
korn shell
# 11  
Old 11-17-2007
Hi,

Previously, you encountered the error [cat: cannot open /tmp/I_out.plt20546] for the simple reason that the file - /tmp/I_out.plt20546 - mentioned in the first line of your code was NOT being created. The plot function was redirecting output to I_plt in the current working directory and not in /tmp.

I believe the following code should work:

I_plt=/tmp/I_out.plt$$
Q_plt=/tmp/Q_out.plt$$

plot(){
echo "#!/usr/local/bin/gnuplot -persist" > /tmp/$1_out.plt$$
echo "plot \"$1_indat.txt\" " >> /tmp/$1_out.plt$$
}

plot I
cat $I_plt
plot Q
cat $Q_plt


Do let me know
- Sandy0077

Last edited by sandy0077; 11-18-2007 at 06:36 PM..
# 12  
Old 11-18-2007
Quote:
Originally Posted by sandy0077
Hi,

Previously, you encountered the error [cat: cannot open /tmp/I_out.plt20546] for the simple reason that the file - /tmp/I_out.plt20546 - mentioned in the first line of your code was NOT being created. The plot function was redirecting output to I_plt in the current working directory and not in /tmp.

I believe the following code should work:

I_plt=/tmp/I_out.plt$$
Q_plt=/tmp/Q_out.plt$$

plot(){
echo "#!/usr/local/bin/gnuplot -persist" > /tmp/$1_out.plt$$
echo "plot \"$1_indat.txt\" " >> /tmp/$1_out.plt$$
}

plot I
cat $I_plt
plot Q
cat $Q_plt


Do let me know
- Sandy0077
Dear Sandy ,

Thank for your reply.. But Sandy you can see my previous quote much similar to you.. Anyway thanks a lot again..

user_prady
--
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Call user defined function from awk

My requirement is to call function ("fun1") from awk, and print its returned value along with $0. fun1() { t=$1 printf "%02d\n", $t % 60; } echo "Hi There 23" | awk '{print $0; system(fun1 $3)}' Any suggestions what to be modified in above code to achieve requirement.. (5 Replies)
Discussion started by: JSKOBS
5 Replies

2. UNIX for Dummies Questions & Answers

Problem syntax with user-defined function

Hi ! I got a script from Arabic to Roman numeral conversion - .comp.lang.awk, that I would like to modify to apply it on my input file. input ("|"-delimited fields): AAAAAA|1, 10, 13, 14, 25, 60 wanted output: AAAAAA|I, X, XIII, XIV, XXV, LX script.awk: #!/usr/bin/gawk -f ... (11 Replies)
Discussion started by: lucasvs
11 Replies

3. UNIX for Dummies Questions & Answers

user defined commands

Hi, i would like to create user defined commands. e,g: if an user executes , mkdircd test then a directory called test should be created and it should be cd to test. How i can create the command mkdircd with below action: mkdir $1 && cd $1. Please help me in achieving this (7 Replies)
Discussion started by: pandeesh
7 Replies

4. Shell Programming and Scripting

How to pass parameter to User defined function in shell script?

Hello, Can anyone guide me tin passing parameters into user defined function of shell script (KSH). Here is my code, InsertRecord() { DB_TBL=$(sqlplus $USERID/$PASSWORD@$DATABASE << EOF set head off set feed off set serveroutput on INSERT INTO TBL1 ( OLD_VAL, NEW_VAL, ... (7 Replies)
Discussion started by: Poonamol
7 Replies

5. Shell Programming and Scripting

Shell Script to display function names (called & defined) in a C++ Source Code

Hello to all, I am looking for a way to display only the names of function (calls & definition) of a C++ source code.There is already a post related to this, but the script is to find the functions using a specific variable, and the replies are not that convincing since they cannot be used for... (2 Replies)
Discussion started by: frozensmilz
2 Replies

6. Shell Programming and Scripting

Clearing a defined function from memory

I guess what I mean is: is there something like unalias to clear functions defined by sourcing a script or config/alias file from memory? Is it necessary to start a new terminal session, or can it be done with a command? I tried "function somefunc {}" but bash told me it hit an "unexpected... (0 Replies)
Discussion started by: SilversleevesX
0 Replies

7. UNIX and Linux Applications

strange behavior of PSQL user defined function

Segregated the problematic portion, and showing for your view here., 1. Following is the function definition, create or replace function new_del(id integer) returns void as $$ begin raise info 'dollar :%',$1; delete from testing where id=$1; end ; $$ language 'plpgsql'; ... (1 Reply)
Discussion started by: thegeek
1 Replies

8. Shell Programming and Scripting

Return an array of strings from user defined function in awk

Hello Friends, Is it possible to return an array from a user defined function in awk ? example: gawk ' BEGIN{} { catch_line = my_function(i) print catch_line print catch_line print catch_line } function my_function(i) { print "echo" line= "awk" line= "gawk"... (2 Replies)
Discussion started by: user_prady
2 Replies

9. UNIX for Dummies Questions & Answers

User defined service

I want to add a new IP service which executes a script on SCO OS5. I have amended /etc/services and added to port number (3333) I have amended /etc/inetd.conf and added a line for this service but I can't get it to execute my own shell script When I telnet to the IP address on port 3333 I... (1 Reply)
Discussion started by: markdrury
1 Replies

10. Shell Programming and Scripting

Nawk user-defined function

HELP!!!! I am in an on-line shell programming class and have a question. Here is the data: Mike Harrington:(510) 548-1278:250:100:175 Christian Dobbins:(408) 538-2358:155:90:201 Susan Dalsass:(206) 654-6279:250:60:50 (There are 12 contribuors total) This database contains names, phone... (1 Reply)
Discussion started by: NewbieGirl
1 Replies
Login or Register to Ask a Question