linux - batch file

i was wondering if there is a Linux version of the batch file on windows and what is the file extension

Hi there,

Oh man - you bet there is. And how!

In Linux they are just called scripts, and they can be written in many languages (PHP, perl, python, etc.). However, you have an extremely powerful scripting language built right into your shell - Bash.

You can do anything you could do in a DOS batch file, and thousands of things more, using bash.

All you do is make a file like this:

#!/bin/bash
echo This is my script
echo
cd /
ls -lha
echo Now let’s do something more fun
echo
rpm -qa | wc
echo That is how many RPMs are installed.

Just save that file and then you can run it with #bash myfile

You don’t need any extension, but by convention you can use .sh for a shell script.

There are many books and on line guides for Bash scripting

Have fun!

Pete

thanks for the help

btw, I also want to add that extensions on Linux are in most cases useless. Unlike Windows where Windows determines the type of a file on its file extension, Linux looks at so called “magical numbers” inside the file and determines its type. If you try to remove or change extension in Windows, it will warn you about that cuz it depends on the extension. In Linux you can use any extensions or no extensions at all but the system will still know what type of file it is cuz of the above mentioned “magical numbers”

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Also in the case of scripts the appropriate interpreter is known based
on the “shebang” line, which is the first line and a special type of
comment. For example:

#!/bin/bash

for bash

#!/usr/bin/perl

for perl

It is a much cleaner system… less-prone to be used for malicious
software as well like the infamous nonsense with virus.jpg.exe files
that, because file extensions are hidden, looks like a picture
(virus.jpg) which everybody opens and uses to get infected.

Good luck.

microchip8 wrote:
> btw, I also want to add that extensions on Linux are in most cases
> useless. Unlike Windows where Windows determines the type of a file on
> its file extension, Linux looks at so called “magical numbers” inside
> the file and determines its type. If you try to remove or change
> extension in Windows, it will warn you about that cuz it depends on the
> extension. In Linux you can use any extensions or no extensions at all
> but the system will still know what type of file it is cuz of the above
> mentioned “magical numbers”
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJRcY93s42bA80+9kRAiThAJwNluK6Odz1TCDavi6CX3U4sdxilgCfW7QD
wndNYCOiAqTYV2SEvoIuWYY=
=9pQs
-----END PGP SIGNATURE-----

I think the question is piculiar. you can execute .bat files in linux, just the content of the file will be the unix-shell syntax. The bat file should have permition to execute.