ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Recently I came upon a new discovery in bash shell that commands which expect input <paths> as parameters like ls, rm works even if you type multiple front slashes
for eg.
rm /foo/bar/file.txt
works even if we type it as
rm /foo//bar/file.txt
or even
ls /foo/////bar///file or to my surprise
even ///foo/bar/file.txt works.
I'm using RHEL 5.
Its a strange behaviour to me as I wonder why it happened. Could anyone explain it more deeply??...
Or if you too come across some strange things then do share it here as everyone would love to know such things ...
It was UNIX behaviour, too, presumably because there is no ambiguity so there's no benefit (except pedantry) in rejecting paths with multiple consecutive "/" characters.
This behaviour is also defined by the POSIX standard, i.e. quoting the definition of PATHNAME from IEEE Std 1003.1-2001:
Quote:
A character string that is used to identify a file. In the context of IEEE Std 1003.1-2001, a pathname consists of, at most, {PATH_MAX} bytes, including the terminating null byte. It has an optional beginning slash, followed by zero or more filenames separated by slashes. A pathname may optionally contain one or more trailing slashes. Multiple successive slashes are considered to be the same as one slash.
Actually I came across this as I found that one of my scripts was not working properly; some of the lines are...
basepath=/backup/rman/
rm $basepath/arc*
While debugging I found that it actually expands to
rm /backup/rman//arc*
And I thought that I found the bug.
Then I executed rm /backup/rman//arc* from command prompt and it worked well (to my surprise).
BUT it was not working from inside the script which was scheduled by cron. This irritated me the most as the same command executes from the command line but not from within the script. This again is unusual...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.