On 09/03/2019 16.22, Andrei Borzenkov wrote:
09.03.2019 17:51, Carlos E. R. пишет:
Hi,
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".
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/Lore.mpeg /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:
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.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
I bet you have symlinks in path.
Yes, so? Ah. 3_MyBook_Videos -> /data/My_Book/Fusion/Videos/ I don't care if it is a symlink, I want to obtain "3_MyBook_Videos/Lore.mpeg" as the result, if not with "realpath" then with something else.
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
And what exactly should the above invocation achieve?
You can see what it prints. So, you have no answer? This is without synmlinks. cer@Isengard:~/FusionTst/Videos> tree 3_MyBook_VideosTst/ 3_MyBook_VideosTst/ ├── Big Bang │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg ├── Big Poof │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg └── notas cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Notes" 3_MyBook_VideosTst/Notes Ok cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/notas" 3_MyBook_VideosTst/Big Bang/notas cer@Isengard:~/FusionTst/Videos> Wrong, I want: ../3_MyBook_VideosTst/Big Bang/notas cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/Big Bang" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/notas" ../3_MyBook_VideosTst/Big Bang/notas cer@Isengard:~/FusionTst/Videos> Yes. cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/Season 2/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/Season 2/episode uno.mpeg" episode uno.mpeg cer@Isengard:~/FusionTst/Videos> Wrong, I want: ../../3_MyBook_VideosTst/episode uno.mpeg So realpath --relative-to={Real_Path} {Real_path/file} is not it. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)