Behaviour of pwd command in sh and ksh

I have a script as below.

 
bash-3.00$ cat test.sh
#!/usr/bin/ksh
path=`pwd`
echo $path
var=$path/temp11
echo $var

If run it is giving output

 
bash-3.00$ ksh test.sh
//var/tmp/SB2/miscellaneous
//var/tmp/SB2/miscellaneous/temp11

If run it in sh instead of ksh, output is

 
bash-3.00$ sh test.sh
/var/tmp/SB2/miscellaneous
/var/tmp/SB2/miscellaneous/temp11

Can anybody tell me what is the problem here.

I have never seen this in any Korn shell I've used (and I've used many versions).

What OS are you using ( uname -a ) and what version of ksh are you using ( ksh --version )?

Note, however, that unless you're using an OS that treats //xxx as a reference to machine xxx on your local network, the extra leading / won't have any adverse effects.

If you change the script to:

#!/usr/bin/ksh
echo "$PWD"
var="$PWD/temp11"
echo "$var"

does it do the same thing?

Make sure nobody aliased 'pwd' !

This might give you more idea about why bash is behaving like that

directory - How linux handles multiple path separators (/home////username///file) - Unix & Linux Stack Exchange

I got below output for the OS and ksh version.

 
bash-3.00$ uname -a
SunOS OSLCOE04.capgemini.com 5.10 Generic_144488-02 sun4v sparc SUNW,Sun-Fire-T200
bash-3.00$ ksh --version
$ 

And also tested below codes..doing same i mean in ksh it is giving //

#!/usr/bin/ksh
echo "$PWD"
var="$PWD/temp11"
echo "$var"

I get my ksh version with escape ^V: $ Version 11/16/88

You might try dtksh in the CDE bin -- it's ksh-93 plus X goodies. Mine is: $ Version M-12/28/93d

I find that sh behavior very buggish!