shell script error
Hi all
I am writing a shell script to traverse all directories present in current directory and list all the files in them. I wrote the following script but it does not work... traverse() { list=$1 path=$2 for i in $1 do if [ -d $i ] then temp=$2 p=$temp"/"$i l=`ls $p` traverse "$l" "$p" else echo -e "\n\n ******************** $path ************************** \n" echo -e "\n$i" fi done return } curr_dir=`pwd` list=`ls` traverse "$list" "$curr_dir" Please help... Thanks in advance. |
to list all files and directories, starting with the current location:
Code:
ls -lR Code:
ls -lR <pathname> |
hi pixellany
Thanks for your useful reply. But can you tell me the error in my script that I wrote... Thanks in advance |
Quote:
**advanced mode--select the text and click on the "#" in the toolbar. |
formatting examples:
Code:
for var in <expression>; do |
It might also help if you explained what the symptoms of "it does not work" are.
|
revised
Sorry for the inconvenience caused to others.
Revised code...... Code:
For example consider the following directory structure: desktop->linux->learner This code if run in desktop folder will successfully enter and print all files in linux folder but will not enter into learner folder. This will simply print the name of learner folder which I don't want it to do. regards _Linux_Learner |
I'm pretty sure that recursion is legal in a BASH function, but it gives me a headache trying to walk thru it......:)
One thing I spotted: p=$temp"/"$i ##You might want to run some tests to verify that this does what you intend. It may be necessary to say: "p=${temp}...etc. More generally, the way to trouble-shoot something like this is to insert some echo statements to make sure that variables are doing what you intended. |
find . -ls
|
p=$temp"/"$i
This p will actually hold the path of next directory to be searched if i is directory. I t shows the right value also. But I don't know why gives wrong answer. regards and thanks _Linux_Learner |
Quote:
Code:
if [ -d $path/$i ] Quote:
Code:
local path=$2 |
Solved
Hi colucix
Thanks for your valuable reply. It works now. Thanks to others also. regards _Linux_Learner ;) |
All times are GMT -5. The time now is 05:42 AM. |