Bug 8001

Summary: lineedit: \w uses getcwd which canonicalizes symlinks (diff PS1=\w behavior between busybox & bash)
Product: Busybox Reporter: Santosh <ysan99>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.20.x   
Target Milestone: ---   
Hardware: All   
OS: All   
Host: Target:
Build:

Description Santosh 2015-04-03 11:37:45 UTC
Please see below the behaviour difference compare to BASH.

BASH:
root@ppc99:~# ll /var/test
lrwxrwxrwx    1 root     root            10 Apr  1 13:35 /var/test -> /hdd1/test
root@ppc99:~# echo $PS1
\u@\h:\w\$
root@ppc99:~# cd /var/test
root@ppc99:/var/test# pwd
/var/test
root@ppc99:/var/test#

Busybox ASH:
root@ppc99:~# ll /var/test
lrwxrwxrwx    1 root     root            10 Apr  1 13:35 /var/test -> /hdd1/test
root@ppc99:~# echo $PS1
\u@\h:\w\$
root@ppc99:~# cd /var/test/
root@ppc99:/hdd1/test# pwd
/var/test
root@ppc99:/hdd1/test#

pwd is ok, but the command  prompt is not as expected.
Comment 1 Mike Frysinger 2016-02-13 04:04:15 UTC
the reason bash works is that it replaces \w with $PWD.  this is the same reason the *builtin* pwd works for both busybox & bash.  (actually, it uses the internal curdir setting that has been validated rather than the explicit $PWD envvar.)

the reason busybox fails w/PS1 is that it has a common lineedit library that it uses with all applets that need line editing capabilities.  so when it parses \w, it will run getcwd() and that is the real path (target of the symlink).

if you run `/bin/pwd` in either env, you'll get the same result because they too don't have access to the internal shell state -- you'll get /hdd1/test.

i think we should just mark this as a known deviation.  lineedit doesn't have access to the shell state, and grabbing PWD from the env would also be wrong (and shells aren't required to export it).