error when call function in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error when call function in bash script
# 1  
Old 02-17-2010
error when call function in bash script

Dear all,

Could you please advice as I when call function i found the following error
" refills: command not found" note that refills is function name.

following also the function and how i call it
Code:
function refills 
{
    echo "formatting refills and telepin" >> $log
    awk -F, '{print $7","$1","$2","$3","$5","$6","$9","$10","$11","$12","$13","$14","$15","$16","$17","$18","$20","$21","$22","$23","$24","$25","$26","$27","$28","$29","$30","$31","$32","$33","$34","$35","$36","$37","$38","$39","$40","$41","$42","$43","$44","$45","$46","$47","$48","$49","$50","$51","$52","$53","$54","$55","$56","$57","$58","$59","$60","$61","$62}' $func_path/$func_tmp > $func_path/$func_out 2>> $log
}
.
.
.
.

#to call the function

refills;

Thanks in advance.

Last edited by zaxxon; 02-17-2010 at 07:21 AM.. Reason: use code tags please, ty
# 2  
Old 02-17-2010
try below :-

Code:
function refills {
    echo "formatting refills and telepin" >> $log
    awk -F, '{print $7","$1","$2","$3","$5","$6","$9","$10","$11","$12","$13","$14","$15","$16","$17","$18","$20","$21","$22","$23","$24","$25","$26","$27","$28","$29","$30","$31","$32","$33","$34","$35","$36","$37","$38","$39","$40","$41","$42","$43","$44","$45","$46","$47","$48","$49","$50","$51","$52","$53","$54","$55","$56","$57","$58","$59","$60","$61","$62}' $func_path/$func_tmp > $func_path/$func_out 2>> $log
}
.
.
.
.

#to call the function

refills;

# 3  
Old 02-17-2010
unfortunately the problem still exist

Dear ahmad,

Thank you very mauch for fast response but unfortunately the problem still exist.

Thanks,
Ahmed Gad
# 4  
Old 02-17-2010
Add a shebang in the head and try again:

Code:
#!/bin/bash
...
...

Or whatever is the path to your bash. Also you can leave out the ; behind calling the function.
# 5  
Old 02-17-2010
Gad there are no problem with the function I had tried it in my bash shell with successful o/p.

but try the other format of the functions and note the ";" & "\" below:-

Code:
refills () { \
    echo "formatting refills and telepin" >> $log ; \
awk -F, '{print $7","$1","$2","$3","$5","$6","$9","$10","$11","$12","$13","$14","$15","$16","$17","$18","$20","$21","$22","$23","$24","$25","$26","$27","$28","$29","$30","$31","$32","$33","$34","$35","$36","$37","$38","$39","$40","$41","$42","$43","$44","$45","$46","$47","$48","$49","$50","$51","$52","$53","$54","$55","$56","$57","$58","$59","$60","$61","$62}' $func_path/$func_tmp > $func_path/$func_out 2>> $log ; \

}

refills ;

# 6  
Old 02-17-2010
It is not working also

Dear zaxxon,

I already added the shebang in the script, also I tried to remove the simicolon, but unfortunately It is not working also,

- also i tried to put 2 () after the function
# 7  
Old 02-17-2010
Assuming that this is a modern bash/ksh/sh you were indeed mixing two alternative syntaxes for a function.

This should be correct. Note also that the semicolon at the end of each of your lines is not required or desirable. I can't think of any circumstance where a semicolon would be the last character on a line.

Code:
refills ()
{
echo "formatting refills and telepin" >> $log
awk -F, '{print $7","$1","$2","$3","$5","$6","$9","$10","$11","$12","$13","$14","$15","$16","$17","$18","$20","$21","$22","$23","$24","$25","$26","$27","$28","$29","$30","$31","$32","$33","$34","$35","$36","$37","$38","$39","$40","$41","$42","$43","$44","$45","$46","$47","$48","$49","$50","$51","$52","$53","$54","$55","$56","$57","$58","$59","$60","$61","$62}' $func_path/$func_tmp > $func_path/$func_out 2>> $log
}

refills

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk call in bash function called with arugments not working, something lost in translation?

Hello, I have this awk code in a bash script to perform a find and replace task. This finds one unique line in a file and substitutes the found line with a replacement. #! /bin/bash # value determined elsewhere total_outputs_p1=100 # file being modified... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

Call function as different user within the script

Hello For HP-UX, ksh shell, is it possible to define functions and call them by another user ? For example <function_name> ( ) { command1 command2 } su - <user> -c <function_name> Or the only option is defining the user in the function itself as follows - <function_name> ( )... (2 Replies)
Discussion started by: atanubanerji
2 Replies

3. Shell Programming and Scripting

Call function from another script

Hey, i got this 2 file. When i try to pick option 1, which is test1, it says ./test: test1: not found. Any idea on how i can fix it? #!/bin/sh QUIT=0 `dirname $0`/testfile while ; do testmenu read option case $option in 1) test1 ;; 2) test2 ;; 3) echo... (2 Replies)
Discussion started by: Nick1097
2 Replies

4. Shell Programming and Scripting

Script – Function Call

Hello, I have Individual function in my shell script , Function1 { Master activities } Function2 { Sub activities 1 } Function3 { Sub activities 2 } … (2 Replies)
Discussion started by: Shanks
2 Replies

5. Shell Programming and Scripting

Shell Script to call another function

Here is the following code : 1. # gcc -c test firstprog.c the above command will generate a executable file called "test " in which ever directory it is run. Assuming It will also return a value. 2. In the below SCRIPT . test is a file generated by compiling a c program... (3 Replies)
Discussion started by: Vabiosis
3 Replies

6. Web Development

Fatal Error: Call to undefined function imagefilter()

I am using PHP5 in ubuntu 9.10. First I installed PHP and GD as separate package. I tried doing manipulation with images using php image function. When I try using the function imagefilter(), it was not worked and got the solution that need to compile the PHP with the bundled version of GD. So... (0 Replies)
Discussion started by: skg
0 Replies

7. Shell Programming and Scripting

Bash: how to call function having it's name in variable?

Hello. Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have: MODULE_NAME="test" FUNCTION_NAME="run" How do I can a function with name test_run? (4 Replies)
Discussion started by: FractalizeR
4 Replies

8. Shell Programming and Scripting

how can i call a function in shell script

i have a function written in one shell script and i want to call that function in another shell script and use the value returned by that script. can any one suggest me how can i do that? regards, Rajesh.P (4 Replies)
Discussion started by: rajesh.P
4 Replies

9. Shell Programming and Scripting

i want to call a oracle function in my shell script

i want to call a oracle function in my shell script (4 Replies)
Discussion started by: dineshr85
4 Replies
Login or Register to Ask a Question