Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Behaviour of pwd command in sh and ksh

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-10-2013
millan millan is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 1 August 2014, 4:15 AM EDT
Posts: 118
Thanks: 3
Thanked 5 Times in 5 Posts
Behaviour of pwd command in sh and ksh

I have a script as below.


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

If run it is giving output


Code:
 
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


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

Can anybody tell me what is the problem here.
Sponsored Links
    #2  
Old Unix and Linux 07-10-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 7 May 2015, 1:22 AM EDT
Location: San Jose, CA, USA
Posts: 6,214
Thanks: 252
Thanked 2,066 Times in 1,764 Posts
Quote:
Originally Posted by millan View Post
I have a script as below.


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

If run it is giving output


Code:
 
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


Code:
 
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:

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

does it do the same thing?
Sponsored Links
    #3  
Old Unix and Linux 07-10-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 17 February 2015, 1:56 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,671
Thanks: 8
Thanked 586 Times in 559 Posts
Make sure nobody aliased 'pwd' !
    #4  
Old Unix and Linux 07-11-2013
vidyadhar85's Unix or Linux Image
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 17 April 2015, 12:45 AM EDT
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 106 Times in 102 Posts
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
Sponsored Links
    #5  
Old Unix and Linux 07-11-2013
millan millan is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 1 August 2014, 4:15 AM EDT
Posts: 118
Thanks: 3
Thanked 5 Times in 5 Posts
I got below output for the OS and ksh version.


Code:
 
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 //


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


Last edited by millan; 07-11-2013 at 06:29 AM.. Reason: adding the result
Sponsored Links
    #6  
Old Unix and Linux 07-16-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 17 February 2015, 1:56 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,671
Thanks: 8
Thanked 586 Times in 559 Posts
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!
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
different behaviour for ksh and ksh -x luckybalaji Shell Programming and Scripting 4 04-12-2011 12:10 AM
KSH: Confused with behaviour of exit maddmaster Shell Programming and Scripting 3 12-09-2010 04:39 AM
sync samba pwd with aix5.3 pwd tjmannonline AIX 2 08-23-2010 08:18 AM
Strange KSH behaviour - any comments? gsw_aix UNIX for Advanced & Expert Users 7 06-24-2008 06:08 PM
Longer commands and strange behaviour on ksh anurags UNIX for Dummies Questions & Answers 2 03-27-2008 11:04 AM



All times are GMT -4. The time now is 01:37 AM.