image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
Thread Tools
  #1  
Old March 16th, 2008, 12:09 PM
Registered User
 
Join Date: Mar 2002
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
waiting_for_OSX is on a distinguished road
sudo source ./myscript

Anyone know why this error message happens? Or better yet, how do I source a file using sudo?

$ sudo source ./myscript
sudo: source: command not found
Reply With Quote
  #2  
Old March 17th, 2008, 12:27 PM
Registered User
 
Join Date: Mar 2005
Posts: 199
Thanks: 0
Thanked 1 Time in 1 Post
artov is on a distinguished road
Do you know what source command does ?

In Unix command shells have two kinds of commands: internal and external commands.
Actually external commands are other programs, where as internal commands are part
of the command set that the command shell implements (ok, some of the external
commands actually also does that); like cd that sets current working directory etc.

You can execute a sequence of the commands either by entering them to the command
shell by hand or entering them to a file and giving them to the shell. When
you give a command, if it is not internal, it is given to the Unix (in this case, OS X) kernel, which checks what kind of file it is. If it is a text file, it's two
first characters are checked. If they are #!, the kernel assumes that the line
contains interpreter path (most likely the command shell, but it could some
other, like Perl). Then kernel starts the command shell and gives the script
to it, so the shell can execute the commands. (If the file was not text, kernel
assumes it is a normal program and loads it and starts it.) In both cases, a
new process is started, having several important features separate
to the command shell where you entered the command (file name).

Several shells have a command that loads a text file and reads each line as if they
are entered by yourself, using current shells' features (like current working directory,
environment variables etc.). Bourne shells call the command "source" (and csh ".").

Sudo command starts a command and executes it using different user account. If
no command is given, it starts command shell. "Current user" is thus changed. Since
this is one of most important process features, what do you thing sudo source does?
Keeps all other features the same but changes the "current user" or starts a new
command shell as the new user, and runs the script using he's features?

Also, as I said, source is internal to bash and bourne shells. Should sudo guess you
like to run the ./myscript using bash? And if you type "sudo . ./myscript", you need
csh shell?

Anyhow, either

$ sudo
source ./myscript
exit

or
$ sudo /bin/bash ./myscript
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 02:10 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.