Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 在shell脚本中使用su_Macos_Bash_Shell - Fatal编程技术网

Macos 在shell脚本中使用su

Macos 在shell脚本中使用su,macos,bash,shell,Macos,Bash,Shell,在shell脚本中如何执行以下操作 $ su my_user Password: my_password 这是必需的,因为我需要在mac上安装homebrew,它不允许我在sudo下安装,但需要我具有管理员权限 $ sudo /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)" Password

在shell脚本中如何执行以下操作

$ su my_user
Password: my_password
这是必需的,因为我需要在mac上安装
homebrew
,它不允许我在
sudo
下安装,但需要我具有管理员权限

$ sudo /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
Password:
Don't run this as root!
以及为什么我不能以当前用户(不是管理员)的身份运行此程序-


作为管理员登录以运行脚本不是一个选项,我必须
su
在脚本中。

您需要从外壳外部执行,如bash、ssh或telnet,由“expect”管理 试一试

还是简单介绍一下

在mac电脑上,root用户和管理员之间存在差异。在标准Unix/Linux系统上,Administrator大致翻译为
wheel
组,这意味着“administrators”组中的人可以使用密码(a la sudo)获得提升的权限。确保您尝试运行此功能的用户是管理员:单击左上角的apple菜单“系统首选项”、“用户和组”。它应该在你的名字下写上“Admin”;如果没有,那就是你的问题。单击锁(窗口左下角),输入计算机上管理员帐户的用户名和密码,单击您的用户,然后选中“允许用户管理此计算机”框。

没有选择以root权限运行脚本?sudo不仅仅执行root操作
sudo-u username
允许您以不同的非root用户身份运行某些东西。那么,真正的问题似乎不是“如何在shell脚本中运行su?”,而是“如何在Mac上安装自制软件,因为它既不会像我自己也不会像sudo那样以root用户身份运行?”--这是一个完全不同的问题。@user1383058如果它故意不让您运行sudo'd to root,为什么您认为它会让您运行sud'd?关键是要使用一个非root管理用户,错误的文本非常清楚地表明了这一点。@CharlesDuffy,因为当我尝试它时,它是有效的
$ /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
This script requires the user to be an Administrator. If this
sucks for you then you can install Homebrew in your home directory or however
you please; please refer to our homepage. If you still want to use this script
set your user to be an Administrator in System Preferences or `su' to a
non-root user with Administrator privileges.
man expect