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:

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 :wink:

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?

@sea:

All paths in the hypothetical script.b are relative; ie,

rm -f ../../some/file.xxx

script.a simply calls script.b:

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 --

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.

You can set the directory prior to calling script.b

(
cd nextDir
bash script.b
)
pushd nextDir
bash script.b
popd
1 Like

@sea:

Could you help out with a context for your idea?

I do confess to being @ sea now; too :wink:

@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 --

I mean like:

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

1 Like

Thanks, folks, for the info!