当不使用-i
选项时,我无法在命令参数中使用通配符。可能是什么原因?sudo参数中的通配符搜索不起作用
下面-i
选项结果:
命令 - sudo -i -u \#800 ls -l /LOG/filename.*
结果 - filename.dat
下面的结果,而不-i
选项:
命令 - sudo -u \#800 ls -l /LOG/filename.*
结果 - filename.* not found
当不使用-i
选项时,我无法在命令参数中使用通配符。可能是什么原因?sudo参数中的通配符搜索不起作用
下面-i
选项结果:
命令 - sudo -i -u \#800 ls -l /LOG/filename.*
结果 - filename.dat
下面的结果,而不-i
选项:
命令 - sudo -u \#800 ls -l /LOG/filename.*
结果 - filename.* not found
你的结果不符合您的所以我并不真正相信你写到问题中的结果。特别是/ LOG /不在结果中。
例如
sudo -i ls -ld /var/folx*
ls: /var/folx*: No such file or directory
我不知道您使用的是哪个sudo,因为AIX没有附带sudo命令。但是我正在使用Mac上的手册页。
-i [command]
The -i (simulate initial login) option runs the shell
specified in the passwd(5) entry of the target user 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. Otherwise, an interactive shell is executed.
sudo attempts to change to that user's home directory
before running the shell. It also initializes the
environment, leaving DISPLAY and TERM unchanged, setting
HOME, MAIL, SHELL, USER, LOGNAME, and PATH, as well as the
contents of /etc/environment on Linux and AIX systems. All
other environment variables are removed.
请注意短语“更改为该用户的主目录”。看起来,即使给出命令,它也可以将cd回家。
sudo pwd
/private/tmp
sudo -i pwd
/private/var/root
这里有一些方法可以自己尝试和调试这种类型的情况。首先是用env
替换您的命令,并将输出捕获到两个单独的文件中,然后进行比较。看看是否有任何差异可能是问题的根源。其次,pwd
和我一样,你发现你的当前工作目录在sudo环境中正在改变。在这种情况下不适用的第三项,但在其他情况下执行echo *
作为命令。在这种情况下,它会给你一个线索,但可能还是会令人困惑。
另一部分是注意到-i正在吸收.profile和.login。许多用户假设各种各样的东西去伪造.profile和.login文件。因此,您可能需要做的另一项工作是将set -x
放在.profile的顶部,以查看它正在做什么。在这种情况下,这不是必需的。