Behavior of truncating multiple slashes in paths stemming from glob pattern matching
-2
votes
1
answer
137
views
From my limited research it seems that in bash, any multiple slashes after a glob pattern are truncated, like so:
echo ////[h]ome////user////Desktop////test////
# outputs ////home/user/Desktop/test/
echo ////home////user////Desktop////tes[t]////
# outputs ////home////user////Desktop////test/
Is this conclusion correct? **Is this behavior defined?** If so, where? Is it shared between different shells? Does it have any relevance?
I've read the bash manual and couldn't find anything about this, though I might've missed something. I understand there is no semantic difference between these notations (other than the exception of a leading double slash), just not whether this behavior is intended or purposeful.
Edit: The behavior described is happening in default bash on Ubuntu. Korn shell (/usr/bin/sh
) did not truncate any slashes.
Edit 2: Just to clarify:
- I'm not asking how Linux handles multiple slashes, it's clear that multiple slashes other than the leading double slash exception have no semantic meaning and may be truncated.
- I'm not asking how this behavior impacts anything within the shell pipeline - it clearly doesn't, other than that if the glob expansion is passed down as an argument, it simply has more slashes.
- I'm not asking why this happens to paths with glob patterns - it's clear that whatever piece of code handles glob expansion also truncates the slashes that follow the glob.
- I'm specifically asking **whether this behavior is defined**, shared across different shells, intentional or purposeful.
Asked by GhtGhoster
(23 rep)
Apr 24, 2024, 06:07 PM
Last activity: Apr 25, 2024, 04:29 PM
Last activity: Apr 25, 2024, 04:29 PM