[RndTbl] Odd shell differences

Gilbert E. Detillieux gedetil at cs.umanitoba.ca
Wed Apr 16 15:25:41 CDT 2014


It's important to note that bash has a built-in pwd command, which uses 
internal state information to determine the working directory, rather 
than doing the walk up the tree that /bin/pwd does.

Here's an example that illustrates the difference:

[root at localhost ~]# cd /usr/local/share
[root at localhost share]# pwd
/usr/local/share
[root at localhost share]# /bin/pwd
/import/share
[root at localhost share]#

On the system used above, /usr/local/share is a symlink to an NFS 
mounted file system.  Bash's built-in pwd command shows the "logical" 
path, whereas /bin/pwd shows the actual path of the mounted file system.

In your example, the internal state of bash still knows the working 
directory by its old name (before the second mv command changed it 
again).  It's not clear what shell you were using prior to running bash 
(and after exiting it), but it may be using /bin/pwd in any case.

Gilbert

On 16/04/2014 3:12 PM, Robert Keizer wrote:
> I ran into this earlier today and thought I'd share.
>
> Shell fails.
>
> sh-4.2$ pwd
> /tmp/a
> sh-4.2$ mv /tmp/a /tmp/b
> sh-4.2$ pwd
> /tmp/b
> sh-4.2$ bash
> robert.keizer at qubit:/tmp/b$ mv /tmp/b /tmp/c
> robert.keizer at qubit:/tmp/b$ pwd
> /tmp/b
> robert.keizer at qubit:/tmp/b$ ls -alh /tmp/ | grep ^d.*c$
> drwxr-xr-x  2 robert.keizer robert.keizer 4.0K Apr 16 16:09 c
> robert.keizer at qubit:/tmp/b$ ls -alh /tmp/ | grep ^d.*b$
> robert.keizer at qubit:/tmp/b$ exit
> sh-4.2$ pwd
> /tmp/c
> sh-4.2$

-- 
Gilbert E. Detillieux		E-mail: <gedetil at muug.mb.ca>
Manitoba UNIX User Group	Web:	http://www.muug.mb.ca/
PO Box 130 St-Boniface		Phone:  (204)474-8161
Winnipeg MB CANADA  R2H 3B4	Fax:    (204)474-7609


More information about the Roundtable mailing list