Directory Tree/Recursion Issue . . .


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Directory Tree/Recursion Issue . . .
# 1  
Old 10-18-2014
Directory Tree/Recursion Issue . . .

Hope the title is close enough; didn't quite know how to put this...

OK.

We have a hypothetical script, script.a, with one simplistic line:
Code:
bash ./nextDir/script.b

Now script.b has a bit more going for it; and does file moves, copies, and renames, calling all the targets with respect to itself.

Manually running script.b from a command prompt at its dir is no problem; all moves, copies, and renames are executed on the targets without issue.

OTOH, running script.b from script.a changes the effective recursion level for script.b to that of script.a; and nothing executes properly...

So, I guess this is a rock-bottom basic question, but the answer eludes me: How do we create a script.a which calls script.b without changing its recursion level?


Thanks again Smilie
# 2  
Old 10-18-2014
How are files from within Script.b adressed?
* relativ (eg: ../../subdir/<fileX>
* simple (eg: <fileX>)
* absolute (eg: /full/path/<fileX>)

How are you executing the script from Script.A?

Can you give us examples?
# 3  
Old 10-18-2014
@sea:

All paths in the hypothetical script.b are relative; ie,
Code:
rm -f ../../some/file.xxx

script.a simply calls script.b:
Code:
bash ./nextDir/script.b

When running script.b directly, the relative path to file.xxx is correct.

When launching script.b via script.a, the relative path to file.xxx is not correct; reflecting the placement of script.a on the tree.

HTH --
# 4  
Old 10-18-2014
Have a compare of the current path you're in when calling the script the diffrent ways.

As in, put a pwd just above the line starting the script.
Compare those paths.

Using relative paths, depends on where you are when you call a script.
# 5  
Old 10-18-2014
You can set the directory prior to calling script.b
Code:
(
cd nextDir
bash script.b
)

Code:
pushd nextDir
bash script.b
popd

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 10-18-2014
@sea:

Could you help out with a context for your idea?

I do confess to being @ sea now; too Smilie

@MadeInGermany:

Looks great, and reminds me of my past microcontroller asm work (Oooo -- now that goes back quite a ways: Waaay too long, no fun...)

Thanks again, folks --
# 7  
Old 10-18-2014
I mean like:
Code:
pwd
sh ../nextDir/script.b

However, MadeInGermany's post takes care of this issue too.
You could also switch/change to absolute paths too.
Or use a variable as 'basedir', to wich you change before executing the relative paths.

hth
This User Gave Thanks to sea For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy directory withOUT recursion

Hi, I cannot find a way to copy a directory to another location with all attributes (mode, ownership, timestamps) but withOUT recursion (after so many years of working with Linux). Say I want to create /home/jail/tmp exactly like /tmp but with nothing in it. Here is what I tried: ... (7 Replies)
Discussion started by: chebarbudo
7 Replies

2. Shell Programming and Scripting

Specific directory parsing in a directory tree

Hi friends, Hello again :) i got stuck in problem. Is there any way to get a special directory from directory tree? Here is my problm.." Suppose i have one fix directory structure "/abc/xyz/pqr/"(this will be fix).Under this directory structure i have some other directory and... (6 Replies)
Discussion started by: harpal singh
6 Replies

3. Shell Programming and Scripting

Likely charset issue with tree command?

Hi All I'm using a tree command in a script that for me outputs:- | - - DIRECTORYNAME However a different user is getting the following output:- aaa (actually with an umlat above them) DIRECTORYNAME I'm not sure where this could be coming from, any ideas anyone? (0 Replies)
Discussion started by: Bashingaway
0 Replies

4. UNIX for Dummies Questions & Answers

directory tree with directory size

find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/' Can someone explain how this works..?? How can i add directory size to be listed in the above command's output..?? (1 Reply)
Discussion started by: vikram3.r
1 Replies

5. Shell Programming and Scripting

creating a directory tree

Hi all, I'd like to create a directory tree, and define from stdin how many levels deep and how many directories in each level should be created. What I wrote does not work properly:#!/bin/bash #set -x read -p " What root directory? " rootDir && { /bin/rm -R $rootDir; mkdir $rootDir; } ||... (2 Replies)
Discussion started by: NBaH
2 Replies

6. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies

7. Shell Programming and Scripting

Recursion to Copy a Directory structure

I have the below code to recurse through a given file path. I am able to go to the leaf level once recursively but traversing out is not possible as the required varaibles don't have the values on return. Both typeset and local don't work for my variable definitions. I have the o/p of the sample... (2 Replies)
Discussion started by: avrkiran
2 Replies

8. UNIX for Dummies Questions & Answers

Protecting the directory tree

Hello, I am hoping someone maybe able to help me. I have set up an Apache web server on my sun server with user accounts in the main htdocs directory. My question is how to stop these users searching up the directory tree when they ftp/telnet to the server. Also is it possible to restrict the... (2 Replies)
Discussion started by: rooneyl
2 Replies

9. Shell Programming and Scripting

directory tree

Hi all, The following is a script for displaying directory tree. D=${1:-`pwd`} (cd $D; pwd) find $D -type d -print | sort | sed -e "s,^$D,,"\ -e "/^$/d"\ -e "s,*/\(*\)$,\:-----\1,"\ -e "s,*/,: ,g" | more exit 0 I am trying to understand the above script.But... (3 Replies)
Discussion started by: ravi raj kumar
3 Replies

10. Programming

directory as tree

hi i have modified a program to display directory entries recursively in a tree like form i need an output with the following guidelines: the prog displays the contents of the directory the directory contents are sorted before printing so that directories come before regular files if an entry... (2 Replies)
Discussion started by: anything2
2 Replies
Login or Register to Ask a Question