Aru*_*oor 14 linux bash shell ubuntu ubuntu-12.04
EUID与UID不同.在什么情况下这些都在脚本中使用?
我试图获取值echo "UID is $UID and EUID is $EUID",但只有空格作为输出.我的机器运行Ubuntu 12.04 LTS.在一些网站上看到,这通常用于检查它是否是root用户以及所有但都无法获得适当的差异.
Fer*_*ndo 11
它只适用于bash,而不适用于破折号(基于Debian的发行版,因为Ubuntu sh通常是破折号的符号链接).
如果以交互方式运行脚本,则可能没有将bash配置为默认shell,请bash在尝试之前运行.
如果从控制台运行它:
bash script.sh
Run Code Online (Sandbox Code Playgroud)
如果您使用其路径运行它(例如./script.sh),请确保脚本的第一行是:
#!/bin/bash
Run Code Online (Sandbox Code Playgroud)
并不是:
#!/bin/sh
Run Code Online (Sandbox Code Playgroud)
有关更通用的方法,请查看:https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root
在该帖子id中提到了命令,其中:
id -u # is the EUID
id -u -r # is the UID
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22389 次 |
| 最近记录: |