首页 > 解决方案 > 如何在 Linux 的主文件夹中运行命令作为另一个用途 + 使用用户的环境/配置变量?

问题描述

/home/B/.config我在另一个用户的主文件夹(和其他文件夹)中有很多 Kwin(窗口管理器)的配置。

有没有办法从我的会话中运行 Kwin,但让 Kwin 也考虑其他用户的配置和环境?

我无法将文件复制到我的帐户,因为它们分散在 B 的主文件夹中,我不想冒险覆盖内容。

我尝试使用sudo,但它不会像运行 B 的会话一样运行命令,而是使用我自己的配置文件来运行程序而不是/home/B/.

标签: linuxbashcommand-line

解决方案


如果-Hsudo 参数不够,也许你还需要 shell 资源文件中的-i一些东西,比如sudo -i -uusername command.

从 sudo 的手册页:

       -i, --login Run the shell specified by the target user's password
                   database entry as a login shell.  This means that
                   login-specific resource files such as .profile or
                   .login will be read by the shell.  If a command is
                   specified, it is passed to the shell for execution
                   via the shell's -c option.  If no command is
                   specified, an interactive shell is executed.  sudo
                   attempts to change to that user's home directory
                   before running the shell.  The command is run with an
                   environment similar to the one a user would receive
                   at log in.  The Command environment section in the
                   sudoers(5) manual documents how the -i option affects
                   the environment in which a command is run when the
                   sudoers policy is in use.

推荐阅读