Error in functions : file2: function: not found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in functions : file2: function: not found
# 1  
Old 10-10-2007
Error in functions : file2: function: not found

Hi

I had written the small script for calling a function.

bash-2.03$ more file2
function sai
{
echo " this is an example"
}
echo "This is main program"
echo "calling the function"
sai()

when executing the above script. I am getting error.

bash-2.03$ sh file2
file2: function: not found
this is an example
This is main program
calling the function

And the Order of execution is also not correct.

Can any one please help me.
# 2  
Old 10-10-2007
Firstly, declare the script to be a bash script

put this at the start of the script...

#!/bin/bash

Code:
bash-2.05$ sh
$ function sai
function: not found

function is not implemented by /bin/sh

Code:
bash-2.05$ function sai
> {
> echo hello
> }
bash-2.05$
bash-2.05$ sai
hello

# 3  
Old 10-10-2007
Thanks it is working now
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Function not found error

Hi All, I have written one shell script where I should call a function by passing variables to the actual function based on some condition. Each time I run the script I am getting the below error dsadm@bunyipd: /var/datastage/FRPDEVL/work/script> sh MClub_Validations.sh Iteration: 1... (1 Reply)
Discussion started by: tpk
1 Replies

2. Shell Programming and Scripting

Pass parameters to a function and running functions in parallel

Hi , I have a script which is using a text file as I/P. I want a code where it reads n lines from this file and pass the parameters to a function and now this script should run in such a way where a function can be called in parallel with different parameters. Please find below my script, it... (1 Reply)
Discussion started by: Ravindra Swan
1 Replies

3. Shell Programming and Scripting

Bash script fails with "function: not found" error

Hello everyone, I am having problems figuring this out. This script below is supposed to create a list of file names with their "md5sum", in a file "lib-list.txt" When I run it "sh component-list.sh " I get this:component-list.sh: 4: component-list.sh: function: not found component-list.sh:... (4 Replies)
Discussion started by: joemb
4 Replies

4. AIX

Calling functions from main program from dlopened library function

Hello All, I am trying to call a function from the calling main program from a dlopened library function, below is the entire code, when I execute it it crashes with sigill. Can you guys help me out I guess I am missing out on the linker flag or something here. besides I am new to AIX and... (1 Reply)
Discussion started by: syedtoah
1 Replies

5. Shell Programming and Scripting

Is it possible make the shell read functions 1 by 1 and calling an other function?

Greetings, I m wondering if it's possible do do the following : I have a simple function called "FindMoveDelete" which does the following : FindMoveDelete() { find . -iname "$FILENAME*.ext" -exec mv {} "$PATH/$VAR" \; && find . -maxdepth 1 -type d -iname "$FILENAME*" -exec rm -rf {}... (6 Replies)
Discussion started by: Sekullos
6 Replies

6. Shell Programming and Scripting

Induct two functions in a single function

echo -en "Enter the logmsg=" {D1234,S1234 | rohit singh} read logmsg logmsg1=${logmsg%%|*}; echo $logmsg1 |sed "s/$/,/g"|sed 's/*$//'>pre-commit.config logmsg_len2=$(echo ${logmsg} | awk '{print $2}'); logmsg_suffix="|"; length() { cat "pre-commit.config"| awk -F'' '{for(i=1;i<NF;i++) {... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

7. UNIX for Dummies Questions & Answers

find lines in file1.txt not found in file2.txt memory problem

I have a diff command that does what I want but when comparing large text/log files, it uses up all the memory I have (sometimes over 8gig of memory) diff file1.txt file2.txt | grep '^<'| awk '{$1="";print $0}' | sed 's/^ *//' Is there a better more efficient way to find the lines in one file... (5 Replies)
Discussion started by: raptor25
5 Replies

8. Shell Programming and Scripting

Function not found message

I have shell script as below: #!/bin/ksh #set -xv function set_variable { VARIABLE_NAME=$1 CURRENT_PATH=`pwd` if ; then echo "\nconfiguration_file.lst file not found in $CURRENT_PATH/common/common_scripts" exit 1; fi VARIABLE_COUNT=`cat... (2 Replies)
Discussion started by: findprakash
2 Replies

9. Shell Programming and Scripting

function: not found error on solaris

shell script in very simple, #!/bin/sh function msgs { echo 'this' } msgs It works on linux, apple, but can not run on solaris. On solaris, when I enter "./t.sh", it gave me following error, ./t.sh: function: not found this ./t.sh: msgs: not found What's wrong with... (3 Replies)
Discussion started by: microstarwwx
3 Replies

10. Shell Programming and Scripting

Installer script -- function not found error

I am writing an installation script on AIX. This involves typical checks of some pre requisites like java, oracle, some version checks, disk space etc. It is a long script. I am facing a strange problem. There are a no of functions used in the script. What I see is that the installer complains of... (1 Reply)
Discussion started by: asutoshch
1 Replies
Login or Register to Ask a Question