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

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.

try below :-

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;

Dear ahmad,

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

Thanks,
Ahmed Gad

Add a shebang in the head and try again:

#!/bin/bash
...
...

Or whatever is the path to your bash. Also you can leave out the ; behind calling the function.

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:-

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 ;

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

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.

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

Dear Diab,

the same problem, i need to mention that i am facing the same problem with all functions in the script.

Dear methyl,

Thanks for your advice

---------- Post updated at 02:54 PM ---------- Previous update was at 02:17 PM ----------

Dears

let me know if you need me to attach the original script to help to solve this problem

Thanks,

Dears,

any updates?

are your file that contain the function executable or not.

meaning permission is r-x or rwx?

BR

Yes the script contain the function executable 755

Yes please do post the whole script. Please blot out anything confidential with X's. Please state how the script was created (which editor?).

Please make it clear which Operating System you are using ( uname -a ) and which shell you have ( echo ${SHELL} ).

Please show some sample data (blotting anything confidential with X's) and show exactly what you type when running the script and exactly what messages and/or output data you receive. Precision is everything in computing.

If you are typing a line of this length from the command line it will not work in many shells because the line is too long (I've tried it), but it can work from a shell script in a modern shell (I've tried it). It is very important to know whether the commands are typed from a command line or inside a shell script and what environment we have here.

deleted

Sorry I'm not going to be much help here. No access to SunOS. Is this Solaris 10 aka SunOS 5.10 or something much older?

Also, can't process the "rar" file in your post.

Possible that the original problem is an awk/nawk issue - maybe an awk specialist can comment on the length of the awk command.

Previous replies about not ending lines with semi-colon (:wink: characters still apply. This is unix shell not Oracle.

gzip, zip, Z, ... more usable.

SunOS include usually also xpg4 version, try it.
ex. /xpg4/bin/awk
There are many commands in SunOS which works little different as ex. xpg4/posix version or gnu version.
Same situation with some other commercial *nix.
find / -name awk
and you'll see the all location where you have awk.
(or maybe nawk, gawk, ...).

#!/bin/ksh
AWK=/xpg4/bin/awk

somefunc()
{
    $AWK ....
}
#....
somefunc
# ....

Just as suspected, notice the "\r":

od -c -N20 Daily_Finance.sh
0000000   #   !   /   u   s   r   /   b   i   n   /   b   a   s   h  \r
0000020  \n   #   #   #

Just as suspected, notice the "\r":

od -c -N20 Daily_Finance.sh
0000000   #   !   /   u   s   r   /   b   i   n   /   b   a   s   h  \r
0000020  \n   #   #   #

Dear binlib,

Could you please explain more?

binlib has notice that your script appears to contain MSDOS line terminators not unix line terminators. This often happens when a script is edited on a PC in a product such as Notepad and then transferred to a unix system without proper conversion. It could equally happen when preparing a post for this forum!

Worth checking the script. To see the line terminators. This unix command makes them visible. A normal unix text line just shows as a $ sign in this program.

sed -n l script_name

Dear methyl,

I checked the output of the sed command you send and I didn't find any MS-DOS caracters, also i ran the following line

tr '^M' < Daily_Finance.sh > Daily_Finance2.sh

but the same problem still exist.

Thanks,