GeekyOmega GeekyOmega - 5 months ago 12
Bash Question

How to change Example.bat to

I have read other threads enter link description herethat discuss .bat to L/unix conversions, but none has been satisfactory. I have also tried a lot of hack type approach in writing my own scripts.

I have the following example.bat script that is representative of the kind of script I want to run on unix.


echo "Example.bat"

perl script1

perl script2 stuff.D2D stuff.D2C

program.exe stuff.D2C

perl script3 stuff.DIS results.out

My problem is I don't know how to handle the perl and program.exe in the unix bash shell. I have tried putting them in a system(), but that did not work. Can someone please help me?
Thank you!


Provided that you have an executable file named program.exe somewhere in your $PATH (which you well might — Unix executables don't have to end in .exe, but nothing says they can't), the code you've pasted is a valid shell script. If you save it in a file named, say, example.bat, you can run it by typing

sh example.bat

into the shell prompt.

Of course, Unix shell scripts are usually given the suffix .sh — or no suffix at all — rather than .bat. Also, if you want your script to be executable directly, by typing just

rather than sh, you need to do three things:

  1. Start the script with a "shebang" line: a line that begins with #! and the full path to the shell interpreter you want to use to run it (e.g. /bin/sh for the basic Bourne shell), like this:

    echo "This is a shell script."
    # ... more commands here ...
  2. Mark your script as executable using the chmod command, e.g.

    chmod a+rx
  3. Put your script somewhere along your $PATH. On Unix, the default path will not normally contain the current directory ., so you can't execute programs from the current directory just by typing their name. You can, however, run them by specifying an explicit path, e.g.

    ./    # runs from the current directory

    To find out what your $PATH is, just type echo $PATH into the shell.