From a bash script in OS X, is it possible to prompt for Administrator permissions?

applescript, bash, permissions, scripting

Solution

Adayzdone's answer is a correct way to use "with administrator privileges"

But you do not need to hard code password or create your own dialog.

If you do not include the user name and password you will be prompted with the standard username and password dialogue for an admin.

do shell script "echo hi" with administrator privileges

Problem

I have a shell script that adds a line to /etc/hosts. If I run it manually with sudo, it works correctly. I'd like to distribute this file to my coworkers who use Macs. However, when the shell script runs normally, I get a: ``` sed: /etc/hosts: Permission denied ``` Is there a way to force a bash script to prompt for a password, as compiled ObjC code can do? If Bash can't do this, can Applescript do so?

Original source