Mailinglist Archive: opensuse-support (183 mails)

< Previous Next >
[opensuse-support] Re: Scripting problem
On 10/03/2019 05.20, Andrei Borzenkov wrote:
09.03.2019 21:45, Carlos E. R. пишет:
On 09/03/2019 16.22, Andrei Borzenkov wrote:
09.03.2019 17:51, Carlos E. R. пишет:

I have a scripting problem.

You have realpath question. You really are not a newbie to not
understand the difference and put in the most meaningless subject possible.

No. It doesn't matter to me if the answer does not use "realpath".

Then you need to ask the right question. Nobody seems to understand what
you are trying to achieve.

Then ask. I do what I can. I'm not god, not even a perfect human being.

I want to create relative paths. Googling told me I need to use:

realpath --relative-to=something someotherthing

But I can't find the correct concoction.

I have the following structure (TV recordings):

/home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes
/home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg

From that list of absolute paths, I want to produce a relative one:

Relative to what? /home/cer/FusionTst/Videos? Well

No. Relative to the directory where each symlink lives, which is not the same
for each one.

Given this tree:

/home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes
/home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg

I want to generate these relative symlinks in this replica tree:

Lore.mpeg --> 3_MyBook_Videos/Lore.mpeg
Lore.mpeg --> ./3_MyBook_Videos/Lore.mpeg

Big Bang/notes --> ../3_MyBook_Videos/Big Bang/notes

Big Bang/Season 6/06x01.mpeg --> ../../3_MyBook_Videos/Big Bang/Season

I already have a script that generates the tree using "absolute" paths - not
caring that "3_MyBook_Videos" is in fact another symlink. I then wanted to do
it with relative symlinks. I did it with code of my own that failed in some of
the cases, so I googled for some ready to paste solution, and hit upon
"realpath". This also failed, I do not understand the man page, got a headache
and a block, so I asked here.

Not that difficult to understand.

echo /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg | cut -d/ -f6-

3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg
../3_MyBook_Videos/Big Bang/notes
../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg

I got a headache, but no working solution.


cer@Isengard:~/FusionTst/Videos> realpath

I bet you have symlinks in path.

Yes, so?

Did you try to read documentation for realpath as was already hinted?

I did not understand it.

‘realpath’ expands all symbolic links and resolves references to ‘/./’,
‘/../’ and extra ‘/’ characters.


3_MyBook_Videos -> /data/My_Book/Fusion/Videos/

So the realpath behaves correctly.

I don't care if it is a symlink,

Computers do not read your mind. They do exactly what you tell them to do.

Which is why I ask humans here. I obviously know that I'm doing it wrong.

Cheers / Saludos,

Carlos E. R.
(from 15.0 x86_64 at Telcontar)

< Previous Next >