I noticed that in bash/zsh if I cd //
it puts me in a directory with the name '//' - pwd shows that as well as my prompt.
If I use more than two slashes like cd ///
etc it just puts me in /.
Is there a significance to the directory // in bash?
? - This is one special parameter/variable in bash. $? - It gives the value stored in the variable "?". Some similar special parameters in BASH are 1,2,*,# ( Normally seen in echo command as $1 ,$2 , $* , $# , etc., ) .
$? determines the exit status of the executed command. $ followed by numbers (e.g. $1 , $2 , etc.) represents the parameters in the shell script.
$? is used to find the return value of the last executed command. Try the following in the shell: ls somefile echo $? If somefile exists (regardless whether it is a file or directory), you will get the return value thrown by the ls command, which should be 0 (default "success" return value).
The POSIX standard tells //
might be interpreted a specific way by a conformant operating system, while ///
is equivalent to /
:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_12
If a pathname begins with two successive characters, the first component following the leading characters may be interpreted in an implementation-defined manner, although more than two leading characters shall be treated as a single character.
That's the reason why bash
is keeping //
unchanged just in case the underlying OS implements this special meaning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With