LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-11-2013, 01:29 AM   #1
joemb
LQ Newbie
 
Registered: Oct 2013
Posts: 2

Rep: Reputation: Disabled
bash script fails with "function: not found" error on Debian 7 virtual machine


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 (bash -x component-list.sh) 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/zookeeper

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
Your help in figuring out the problem would be highly appreciated.

Thank you.
 
Old 10-11-2013, 01:35 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,785

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
probably you need to execute it as bash <scriptname> instead of sh <scriptname>, or just <scriptname>
 
1 members found this post helpful.
Old 10-11-2013, 01:46 AM   #3
joemb
LQ Newbie
 
Registered: Oct 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi pan64,

Thanks so much for your quick and helpful response.

Regards,

Joe
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Startx fails with "fbcon not found" error - need help to fix this linuxlicious Linux - General 2 11-22-2012 10:56 AM
1st script attempt; cygwin; fails "bash: myscript : command not found" engineerd1 Linux - Newbie 8 11-08-2009 04:03 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LFS 6.0 error: glibc fails check with "g++: command not found" peristaltic Linux From Scratch 1 03-15-2005 07:52 PM
"No Java virtual machine could be found from your PATH" - ignores bashrc shaider Linux - Software 7 10-09-2004 12:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration