.bat equivalent for linux

This is a discussion on .bat equivalent for linux within the Linux Programming forums, part of the Platform Specific Boards category; I just switched to using linux at school for all my programming assignments. As it is, I'm typing out the ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    .bat equivalent for linux

    I just switched to using linux at school for all my programming assignments. As it is, I'm typing out the g++ command every time I want to test my program, which is most inconvenient. If I was on a windows machine, I would make myself a compile.bat like this:
    Code:
    g++ %1.cpp -o %1
    %1
    Is there any way to make a similar file in linux? Or is there an equivalent to system()?
    Illusion and reality become impartiality and confidence.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Bash files. Here's a sample one:

    Code:
    #!/bin/bash
    g++ "$1".cpp -o "$1"
    ./"$1"
    Save it as 'compile.sh', and you can run it like this: './compile.sh filename.cpp'.

    Edit:
    I've written a BASH script for this, I'll post it when I get home from work.
    Last edited by XSquared; 01-22-2004 at 07:22 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    type in "man bash" at the command line and in that you will find an overview of bash, the commands, iterators, et al of the language.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    In general, you can give every text file the executable bit and your shell will try to do the commands in it if you call it. If the first line of the file starts with #! then it is a shell cast and the #! is followed by the interpreter that should evaluate the file. For cross-platform (various Unixes) scripts this is usually /bin/sh, a very basic shell which is available on just about every Unix. In the example above it's /bin/bash, the Bourne Again SHell, the default shell of the typical Linux installation. But it might as well be /usr/bin/perl if the file is a Perl script, /usr/bin/awk if it's an awk script or any other text interpreter. I've used PHP and tried Javascript (Rhino) once, but it didn't work
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Banned
    Join Date
    Dec 2003
    Posts
    367
    You could also use /usr/bin/env followed by a space and the interpreter. For example: #!/usr/bin/env python

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    What for though? env just modifies the environment and then calls the passed app. Without arguments to env, it's just the same as directly calling the interpreter, isn't it?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Banned
    Join Date
    Dec 2003
    Posts
    367
    You don't have to know the path of the interpreter.

  8. #8
    Deleted Account
    Join Date
    Jan 2004
    Posts
    40
    Originally posted by XSquared
    Bash files. Here's a sample one:

    Code:
    #!/bin/bash
    g++ "$1".cpp -o "$1"
    ./"$1"
    Save it as 'compile.sh', and you can run it like this: './compile.sh filename.cpp'.

    Edit:
    I've written a BASH script for this, I'll post it when I get home from work.
    Don't forget to
    Code:
     chmod 755 compile.sh

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Good point bloodstayne. You have to know the path of env though.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer equivalent to array notation
    By bekkilyn in forum C Programming
    Replies: 4
    Last Post: 12-06-2006, 08:22 PM
  2. C++ Equivalent JPEG Functions?
    By stickman in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2006, 11:50 AM
  3. Replies: 10
    Last Post: 08-18-2005, 12:17 AM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  5. Replies: 0
    Last Post: 11-01-2002, 11:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21