Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

linux - How to convert ".." in path names to absolute name in a bash script?

How to convert the .. in the path names to absolute path names in a bash script. That is, if I have a path /home/nohsib/dvc/../bop, I want this to be changed to the path without dots in it, in this case /home/nohsib/bop

How can I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What you're looking for is readlink:

absolute_path=$(readlink -m /home/nohsib/dvc/../bop)

Please note: You need to use GNU's readlink implementation which offers the "-m" option. BSD's readlink for example does not.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...