[wplug] Linux Bat Files

Michael H. Semcheski lists at immuneit.com
Thu Aug 25 18:46:56 EDT 2005


I think this question has been answered well by other posts in this
thread, but I just wanted to wrap everything up:

The first line of a script is #! followed by the interpreter or shell
that will execute the following lines.  sh is the standard, but other
shells have bolted on new syntax or options.  Other shells include csh,
ksh, tcsh, ash, bash.  An interpreter you might want to look at is
perl.  Its considered to be good form to use the absolute path to the
executable, but you don't have to.  If its in your path, it will work. 
(ie #!perl is good, but #!/usr/local/bin/perl is better.) 

The path to sh is generally /bin/sh, but if you use other shells, they
might be located in /usr/bin/.  Suppose you want to find the location of
the perl interpreter on your system.  Run 'which perl' and it will
return something like /usr/local/bin/perl.

Once you've written your script and are ready to run it, if you do not
give an absolute path or path relative to the current directory, the
interpreter will look in the directories in $PATH.  It will not look in
the current directory unless that directory is in $PATH.  Thats why you
put a ./ in front of the command. 

A file must be marked executable before you can run it.  Hence, chmod +x
filename.

Now a little conjecture:

If you do not like sh, there are plenty of other options.  I haven't
written many sh scripts since I learned perl.  But before me go hundreds
of millions of lines of shell script were written to do fantastic
things, so its fully capable, if dated.  If you can get around on the
command line and don't have to do anything too fancy, sh will work just
find (since you can run commands just like you were typing them into the
command line.)

Mike


Mark A wrote:
> First of all I am a total noob to Linux just switched over about 2
> days ago. there was a time in windows and dos that you could make a
> simple bat to automate things, move files, rename files, so forth and
> so on. Well I am trying to create a simple bat file in Linux and I
> cant get it to work. I am working in a Shell only environment no
> GUI. There was a previous post on this board about it I did what it
> said and it didn't work. here is what I pretty much did
>
> Jed marktest.bat (typed into file) mkdir /var/www/docs/hobohound.org
> (saved the file, exited jed editor)
>
> Back in shell mode typed: chmod +x marktest.bat
>
> I got an error "command not found". I have tried many different ways
> of wording it and am getting no where.
>
> This is but a simple BAT file to make a DIR when finished I will
> need this BAT file to make Hundreds of DIRs, but I cant even get the
> basics to work.
>
> Any help with this would be great. Thank you all.
>
> Mark A. mamaral at brandinteractive.com
> <mailto:mamaral at brandinteractive.com>
>
>
> -------------------------
>
> _______________________________________________ wplug mailing list
> wplug at wplug.org http://www.wplug.org/mailman/listinfo/wplug





More information about the wplug mailing list