Results 1 to 5 of 5

Thread: linux equivalent of a batch file

  1. #1
    Join Date
    Jun 2008
    Beans
    75

    linux equivalent of a batch file

    Hi, you know in windows you can create a batch file with commands which are run when the batch file is executed, what is the linux equivalent?

    Thanks

  2. #2
    Join Date
    Dec 2006
    Location
    Hamburg, Germany
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: linux equivalent of a batch file

    The *nix equivalent would be a shell script. Ubuntu's default shell is bash.

    BASH Programming Introduction might prove a worthy read.
    One ought, every day at least, to hear a little song, read a good poem, see a fine picture, and, if it were possible, speak a few reasonable words...

  3. #3
    Join Date
    Oct 2006
    Location
    Charlotte, North Carolina
    Beans
    199
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: linux equivalent of a batch file

    Linux has a very rich command line language, and commands can be put in a file and executed, like a .bat file in Windows. To start, you create a plain text file and put your commands in it. You then make your file executable.

    For instance, if your file name is "my_file", execute this command to make it executable:

    chmod 755 my_file

    To run it, execute this command:
    ./my_file

    If you are just getting started with Linux commands, enter "linux command line introduction" in your favorite search engine.

  4. #4
    Join Date
    Jun 2008
    Beans
    75

    Re: linux equivalent of a batch file

    This is great, and Thanks for the quick reply

  5. #5
    Join Date
    Apr 2007
    Beans
    2,578
    Distro
    Ubuntu

    Re: linux equivalent of a batch file

    The shell script.

    Equally as in Windows a text file containing commands.

    Usually, you will find an extra first line, similar to #!/bin/bash. This line instructs which command processor should execute the commands. You do not have such choice in Windows.

    Running such a batch file or script involves typing the name of the file similar to Windows. However, if the file is in your current directory, you need to precede the name with ./, e.g.

    ./myscript

    Before you can execute a script in linux, you first must declare it "executable". This is because linux is designed to be safe. It won't try to run any file like Windows does. You can make it executable using the file manager or with the command chmod

    chmod +x myscript

    will mark the file as "executable" . After that, you can run the file with

    ./myscript

    If the file is in another directory that is in your search path, you can execute it simply by typing its name.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •