Bash script fails with "function: not found" error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script fails with "function: not found" error
# 1  
Old 10-10-2013
Linux 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: 5: local: not in a function
Interestingly, I have run it in debug mode and it populated the said text file with a list of lib files

Am running it on Debian 7.

Here is the script:

Code:
#!/bin/bash 
cd /usr/local/activemq

function list_dir {
local path=$1
local level=$2
file=$3

#echo $path
#echo $level
if [ $level -gt 2 ];then return;fi
for i in `ls $path`
do
        local line=""
        for n in `seq 0 $level`
        do
            line+="\x20\x20"
        done
if [ `echo $i | grep -E "\.zip$|\.jar$"` ]
then
      md=`md5sum $path/$i | awk '{print $1}'`
      echo -e $line${i##*/}"\x20\x20\x20\x20"$md >> "./$file"
fi
done

for i in `ls $path`
do
        local line=""
        for n in `seq 0 $level`
        do
            line+="\x20\x20"
        done
if [ -d $path/$i ]
then
    echo -e $line${i##*/} >> $file
    list_dir $path/$i $[level+1] $file
fi
done
}
rm lib-list.txt
echo -e "lib" >> lib-list.txt
list_dir ./lib 0 lib-list.txt

Can someone help me out please.

Last edited by joemb; 10-10-2013 at 10:48 AM.. Reason: had made a major omission
# 2  
Old 10-10-2013
Are you sure /usr/local/activemq exists or is readable/traversable? And you must be able to write there for you have lines such as:
Code:
echo -e $line${i##*/}"\x20\x20\x20\x20"$md >> "./$file"
echo -e $line${i##*/} >> $file

In case you just give a file name...
#--- Addendum: forgotten...
And especially :
Code:
rm lib-list.txt
echo -e "lib" >> lib-list.txt
list_dir ./lib 0 lib-list.txt


Last edited by vbe; 10-10-2013 at 11:40 AM.. Reason: Addendum...
# 3  
Old 10-10-2013
Hi vbe,

Thanks for the respnse.

Yes, /usr/local/activemq exists with these rights: drwxr-xr-x

Under the directory, all files have either "-rwxr-xr-x" or "-rw-r--r--" and directories have either "drwxr-xr-x" or "drwxr-sr-x"
# 4  
Old 10-11-2013
Quote:
When I run it "sh component-list.sh " I get this:

component-list.sh: 4: component-list.sh: function: not found
component-list.sh: 5: local: not in a function
try:
Code:
 ./component-list.sh

your script is not sh compatible it seems...
# 5  
Old 10-11-2013
No 'need' to define variables with local as this doesnt 'exist'.
Remove those and it should run.

However, you could update the 'outdated' `command` to $(command) while beeing on it.. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

3. Shell Programming and Scripting

Bash Script giving "Command Not found"

Hello Geeks, Greetings...I have the following script: #!/usr/bin/bash #Script to generate number of active PDP context & calculate PDP activation #failurefrom EPG-M #Script written by Gbenga Adigun #September 12, 2013 username="xxxxxx" password="xxxxxxxxx" HOSTS=( ggsn01... (6 Replies)
Discussion started by: infinitydon
6 Replies

4. Shell Programming and Scripting

bash "not found" error

In solaris, I am using a bash script which includes the following variable declaration. The script executes successfully on the command line, but when executed through the cron, I receive a "not found" error. amt="`echo "scale=3;$numerator/$base*100" |bc |cut -d. -f1`" Here is the output from... (9 Replies)
Discussion started by: smenago
9 Replies

5. Shell Programming and Scripting

sendmail script throwing an error "No recipient addresses found in header"

Hi, I am using following code to send an e-mail with attachment and body. echo "To: user1@mail.com,user2@mail.com" > mail.tmp echo "Cc: user3@mail.com,user4@mail.com" >> mail.tmp echo "From: group@mail.com" >> mail.tmp echo "Subject: my report" >> mail.tmp echo "please see as attached"... (6 Replies)
Discussion started by: vivek_damodaran
6 Replies

6. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

7. UNIX for Dummies Questions & Answers

Alias, function or script (bash) to "revert" cd command?

In all of my brief and superficial experience with Unix or Linux, the one curious and consistent thing has been that 'cd ./' (back up one directory level) has done absolutely nothing in any of them. Now I understand that, at least for bash, 'cd ./' appears to have been substituted by 'cd ..' Am... (1 Reply)
Discussion started by: SilversleevesX
1 Replies

8. HP-UX

ERROR: more than one instance of overloaded function "vprintf" has "C" linkage

Hi people! I've got this own library: -------------------------------------------- Personal.h -------------------------------------------- #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdarg.h> #include <string.h> ... (0 Replies)
Discussion started by: donatoll
0 Replies

9. Shell Programming and Scripting

when executing .sh script in telnet error "script not found"

Hi. i have written a wrapper script which inturn call the ftp child script in it. Now the problem is when i executing the same script in my script directory through putty it is getting executed successfully;where as through telnet i get an error "scripts not found" Can some one help me... ... (1 Reply)
Discussion started by: smiley
1 Replies

10. UNIX for Dummies Questions & Answers

#!/bin/sh script fails at StringA | tr "[x]" "[y]"

I need to take a string (stringA) check it for spaces and replace any spaces found with an equal (=) sign. This is not working. There are spaces between each component: $StringA | tr "" "" The error returned is: test: Specify a parameter with this command Can you help? (3 Replies)
Discussion started by: by_tg
3 Replies
Login or Register to Ask a Question