NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/56464: sh(1) reads ./.profile rather than ~/.profile

>Number:         56464
>Category:       bin
>Synopsis:       sh(1) reads ./.profile rather than ~/.profile
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 25 05:00:00 +0000 2021
>Originator:     elo
>Release:        NetBSD 9.0_RC1
System: NetBSD marmite.localnet 9.0_RC1 NetBSD 9.0_RC1 (BLUEBELL) #0: Tue Dec 24 17:18:23 GMT 2019  elo@marmite.localnet:/usr/obj/sys/arch/amd64/compile/BLUEBELL amd64
Architecture: x86_64
Machine: amd64
	The sh(1) man page states that a login shell reads commands from
	the files /etc/profile and ~/.profile. In reality, sh looks for
	.profile in the current working directory, and not in the user's
	home directory. Commands like login(1) and sudo(8) typically set
	the cwd to the user's $HOME, removing the distinction in common
	use, but '~' and '.' may not coincide for shells started by other
	means, e.g., via su(1) with the '-d' option.

	Revision 1.212 of the sh man page added a qualifying clause (not
	mentioned in the log message for that commit) to say that .profile
	is looked for specifically in the user's home directory (not in
	the cwd, as was before implicit), but the code was never changed
	to implement that behaviour. Every Bourne-like shell I've checked
	(including dash, another Almquist descendant) looks for .profile
	in the home directory of the user.
	$ cd /tmp
	$ echo 'echo user:$USER home:$HOME cwd:$PWD' > .profile
	$ su -d <user>

	The choice of <user> is immaterial (save for the obviously
	necessary condition that <user>'s login shell must be /bin/sh).
	Reconcile the sh code and the sh man page, either by removing the
	misleading text added in revision 1.212 of the man page, or by
	amending the code so that the shell really does look for .profile
	in the user's home directory (or in '/', if $HOME is not set).

Home | Main Index | Thread Index | Old Index