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. пишет:
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".
Then you need to ask the right question. Nobody seems to understand what you are trying to achieve.
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:
Relative to what? /home/cer/FusionTst/Videos? Well 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.
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?
Did you try to read documentation for realpath as was already hinted? --><-- ‘realpath’ expands all symbolic links and resolves references to ‘/./’, ‘/../’ and extra ‘/’ characters. --><--
Ah.
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.
I want to obtain "3_MyBook_Videos/Lore.mpeg" as the result, if not with "realpath" then with something else.
I gave you one solution above. Another solution would be to read realpath documentation and use --no-symlinks option.
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.
And?
So, you have no answer?
To what?
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
And how should we or realpath know what you want? Start with explaining why you suddenly need ".." in the second case and how to determine when you need ".." using rules that can be translated into computer commands. Oh, and why it is OK to *not* have ".." in the first case.