Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of // in bash?

Tags:

bash

shell

unix

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?

like image 296
Mixologic Avatar asked Oct 20 '14 15:10

Mixologic


People also ask

What is the meaning of $? 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., ) .

What is the significance of $? In script?

$? determines the exit status of the executed command. $ followed by numbers (e.g. $1 , $2 , etc.) represents the parameters in the shell script.

What is $? In 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).


1 Answers

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.

like image 51
jlliagre Avatar answered Nov 18 '22 06:11

jlliagre