Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Abnormal HOME variable modification requirements.

26 views
Skip to first unread message

hongy...@gmail.com

unread,
Oct 26, 2021, 8:47:51 AM10/26/21
to
I've written the following Emacs package debug script which can be
run by `$ bash /home/werner/.emacs.d/debug/.emacs.d/init.el`:

```emacs-lisp
#!/usr/bin/env bash
:;# $ realpath init.el
:;# /home/werner/.emacs.d/debug/.emacs.d/init.el
:; HOME=$(dirname $(dirname $(realpath -e $0))) proxychains-ng-socks5
/usr/local/bin/emacs -- "$@"; exit

;;Bootstrap straight
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el"
user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)

(use-package company
:demand t
:hook
(after-init . global-company-mode))
```
But the `proxychains-ng-socks5` wrapper script relies on the normal HOME variable setting. How to solve this dilemma?

Regards,
HZ

Lew Pitcher

unread,
Oct 26, 2021, 9:55:32 AM10/26/21
to
Well, you /could/ derive your version of HOME differently. Yes, let's go
with that.

Initially, HOME is derived from the 6th field in the user's
/etc/passwd entry. You could
- use whoami(1) to determine the username
- use grep(1) and cut(1) (alternately, just awk(1) )to parse /etc/passwd
and extract the home directory of the selected username
- use that extracted home directory value to set your HOME variable

HTH
--
Lew Pitcher
"In Skills, We Trust"

hongy...@gmail.com

unread,
Oct 26, 2021, 11:14:05 AM10/26/21
to
Do you mean this one?

$ grep ^"$(whoami)" /etc/passwd |cut -d ':' -f6
/home/werner

HZ

Grant Taylor

unread,
Oct 26, 2021, 12:04:29 PM10/26/21
to
On 10/26/21 6:47 AM, hongy...@gmail.com wrote:
> But the `proxychains-ng-socks5` wrapper script relies on the normal
> HOME variable setting. How to solve this dilemma?

Please elaborate on what the abnormal HOME variable contents are?

Are you artificially changing the HOME variable's contents at the start
of the script? It looks like it's commented out to me. (But I don't
speak LISP.)

I'm failing to fathom a case where the contents of HOME would not be normal.



--
Grant. . . .
unix || die

Lew Pitcher

unread,
Oct 26, 2021, 1:07:43 PM10/26/21
to
Sure. Or
$ awk -F : -v user=$(whoami) '$1 == user {print $6;}' /etc/passwd
/home/lpitcher

Kenny McCormack

unread,
Oct 26, 2021, 2:37:57 PM10/26/21
to
In article <sl9ckq$nc9$1...@dont-email.me>,
Or just:

$ echo ~
and
$ echo ~lpitcher

--
People sleep peaceably in their beds at night only because rough
men stand ready to do violence on their behalf.

George Orwell

Eli the Bearded

unread,
Oct 26, 2021, 3:11:02 PM10/26/21
to
In comp.unix.shell, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> Lew Pitcher <lew.p...@digitalfreehold.ca> wrote:
[ HOME=$(dirname $(dirname $(realpath -e $0))) proxychains-ng-socks5 ]
>> $ awk -F : -v user=$(whoami) '$1 == user {print $6;}' /etc/passwd
>> /home/lpitcher
> Or just:
>
> $ echo ~

I've just got to really wonder what's going on here. If I have set
HOME differently than the one in /etc/passwd, I probably have a good
reason for that and will not like having it reset.

I frequently use /var/tmp/$(whoami) as an alternative $HOME for testing
things, in particular testing how stuff works without all my dot files.
Or for say, testing how dot file installation from a home-config git
repo works.

I use other directories, too, but rarely. It's a handy way to have
multiple simultaneous news readers working with different .newsrc files,
for example.

Elijah
------
HOME=/var/tmp/elijah PS1=': subshell; ' $SHELL

Javier

unread,
Oct 26, 2021, 7:26:34 PM10/26/21
to
Some software uses /etc/passwd instead of the HOME variable.
It's a bug.

Possibly you can inspect 'proxychains-ng-socks5' if it's an script and
fix the bug yourself.

That bug was very common in the past. Fortunately nowadays most
software has fixed it. Ivan Shmakov commented about that in
comp.emacs a pair of years ago:

Ivan Shmakov <iv...@siamics.net> on comp.emacs
Message-ID: <8736wyx2...@violet.siamics.net>

Unfortunately, some software refers to passwd(5) data directly
instead, leaving no way for the user to override the home
directory location. In particular, this was the behavior (IIRC)
of programs based on older Glib versions. And I vaguely recall
that Emacs might have been affected as well.

hongy...@gmail.com

unread,
Oct 26, 2021, 8:39:22 PM10/26/21
to
Thank you for much for your explanation. This is just the case of my dilemma.

hongy...@gmail.com

unread,
Oct 26, 2021, 8:45:14 PM10/26/21
to
This doesn't work for the Emacs case. If the HOME has been changed from within the session where Emacs is started, it won't use the new HOME as ~.

Lew Pitcher

unread,
Oct 27, 2021, 10:31:51 AM10/27/21
to
If $HOME is not reliably set, then ~ is unlikely to be either.
Witness:

10:27 $ echo $HOME
/home/lpitcher
10:27 $ echo ~
/home/lpitcher

Both $HOME and ~ point at my home directory

But now, I change $HOME to point somewhere else
10:27 $ HOME=/var/some/directory
10:28 $ echo $HOME
/var/some/directory

And, lo and behold, ~ changes as well
10:28 $ echo ~
/var/some/directory

So, if the OP can't depend on $HOME to point to the proper
directory (hence, his asking how to derive the home directory)
then he can't depend on ~ either.

HTH

Lew Pitcher

unread,
Oct 27, 2021, 1:12:28 PM10/27/21
to
FWIW, from bash(1):
Shell Variables
The following variables are set by the shell:
...
HOME The home directory of the current user; the default argument for
the cd builtin command. The value of this variable is also used
when performing tilde expansion.

Keith Thompson

unread,
Oct 27, 2021, 1:19:27 PM10/27/21
to
Lew Pitcher <lew.p...@digitalfreehold.ca> writes:
> On Wed, 27 Oct 2021 14:31:45 +0000, Lew Pitcher wrote:
[...]
On the other hand, ~username, as opposed to just ~, does not depend on
$HOME. It does a lookup in /etc/passwd or whatever the system's
equivalent is.

$ echo $HOME ~ ~kst
/home/kst /home/kst /home/kst
$ HOME=/tmp
$ echo $HOME ~ ~kst
/tmp /tmp /home/kst
$ eval echo ~$USER
/home/kst
$ eval echo ~$(whoami)
/home/kst
$

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Lew Pitcher

unread,
Oct 27, 2021, 2:10:52 PM10/27/21
to
Thanks, Keith

I'm glad to have learned something new today.

hongy...@gmail.com

unread,
Oct 28, 2021, 4:07:21 AM10/28/21
to
Me too; so am I; So do I.

hongy...@gmail.com

unread,
Oct 28, 2021, 4:23:42 AM10/28/21
to
Some supplement

werner@X10DAi-00:~$ echo $(eval echo ~$USER)
/home/werner
werner@X10DAi-00:~$ echo $(eval echo ~$USERNAME)
/home/werner
werner@X10DAi-00:~$ echo $(eval echo ~$(whoami))
/home/werner

0 new messages