a little script

John Macdonald jmm-TU2q2He6PgRlD5gtYiU6kEEOCMrvLtNR at public.gmane.org
Tue Jan 27 18:29:45 UTC 2004


On Tue, Jan 27, 2004 at 10:48:45AM -0500, Tim Writer wrote:
> Chris Aitken <aitken-BwLjziHGQLusTnJN9+BGXg at public.gmane.org> writes:
> 
> > Paul Mora wrote:
> > >
> > > Here's a very simple example script to do what you want (I know, I'll
> > > probably be flamed by the scripting experts out there):
> > >
> > > #!/bin/bash
> > > #
> > > # Simple script to stop printing services and unload the parallel
> > > # port module
> > > service cups stop
> > > modprobe -r lp
> > > exit 0
> > 
> > I type all that into vi?
> 
> Any text editor, vi is fine.
> 
> > Are the #'s remarks or do they represent the command
> > prompt ($ on my rh 7.3 system)?
> 
> They are remarks (comments).

But don't just throw them all away.

When the script is run by bash, they are treated by
bash as comments.

However, that first line is not totally a comment -
it can serve a functional purpose too.  When the
first line of a text file starts with #! (in column
1, no leading spaces) the rest of the line can be
used to indicate the program that will interpret
this script (in this case /bin/bash).  (There are
a few more details, like including command options
and platform-specific limitations on the maximum
length of the line that will be used.)  Now, if you
make this file executable, you can invoke this file
as if it were a program.  The kernel recognizes the
leading #! (called a shebang, short for hash bang)
as a special type of "executable" program, and invokes
the associated program to run the script.  That means
that instead of saying "bash script" you can just say
"script" to get it to run.  Lots of "programs" that
come as a part of your system are actually scripts
under the hood, but you don't have to care about that
becuse of this mechanism.
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list