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.
perl script1 param.in newParam.in
perl script2 newParam.in stuff.D2D stuff.D2C
perl script3 stuff.DIS results.out
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
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
sh example.sh, you need to do three things:
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:
#!/bin/sh echo "This is a shell script." # ... more commands here ...
Mark your script as executable using the
chmod command, e.g.
chmod a+rx example.sh
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.
./example.sh # runs example.sh from the current directory
To find out what your
$PATH is, just type
echo $PATH into the shell.