Can bash natively re-format a relative path to an absolute path, or not - being dependent on tool "realpath"?
0
votes
1
answer
130
views
**UPDATE** Once again, I can't post an answer to my question! Clicking the button just triggers an error message: "Unable to load popup - please try again". So, I have no other choice than to share the solution like this:
="token="0"; if [[ "$input_path" =~ /$ ]]; then token="1"; input_path="${input_path%/}"; fi; cd "${input_path%/*}"; printf "$PWD/"; if [[ "$token" -eq 1 ]]; then printf "${input_path##*/}/"; else printf "${input_path##*/}"; fi
"
Evaluation:
0:1 - bash exhaustion:unix philosophy
If coding thoroughly is an ambition, the bash exhaustion way just proves that in this case it's far better to rely on unix philosophy, here meaning application of tool
, instead of replicating what it does with bash - you see, it works, but it's a mess, very complicated and a lot more code.
----
Use the tool
, from a certain working directory, setting the scope with a relative path, search for any files, and apply -exec realpath
- will have the same working directory as
, unless using -execdir
- on the resulting matches - relative paths - and output will be that same list of relative paths, but transformed into absolute paths.
Out of curiosity: Can bash do this alone?
Asked by futurewave
(213 rep)
May 10, 2024, 07:28 PM
Last activity: May 11, 2024, 05:37 PM
Last activity: May 11, 2024, 05:37 PM