DOOFUSoftware :: script templates


Templates to get you started on all the important scripting languages. All the basics.

PERL
#!/usr/bin/perl
#
# Stephen W. Thomas (sthomas@cs.queensu.ca)
# School of Computing, Queen's University, Canada
# Fall 2009
#
# Script to ...
################################################################################

# Check arguments
if ($#ARGV < 3){ 
   print "Usage: $0 option1? option2?  outfile infile [...] \n";
   print "Exiting.\n";
   exit 1;  
}

$option1 = $ARGV[0]; 
$option2 = $ARGV[1]; 
$outfile = $ARGV[2]; 

# Get all the input files
for ($i=3; $i <= $#ARGV; $i++){
    push(@FILES, $ARGV[$i]);
}


# Open the output file
open(OUTFILE, ">$outfile") or die("Cannot open output file.");



BASH
#!/bin/bash
#
# Stephen W. Thomas (sthomas@cs.queensu.ca)
# School of Computing, Queen's University, Canada
# Fall 2009
# 
# Script to ...
###############################################################################

# Check arguments
if [ $# -ne 1 ]; then
    echo "Usage: $0 input_file"
    echo "Exiting."
    exit 1
fi

# Name of the paper, no extension
LATEXFILE=$1;   

if [ ! -e $LATEXFILE.tex ]; then
    echo "$0: File \"${LATEXFILE}\" doesn't exist."
    echo "Exiting."
    exit 1
fi



CSH
#!/bin/tcsh
#
# Stephen W. Thomas (sthomas@cs.queensu.ca)
# School of Computing, Queen's University, Canada
# Fall 2009
#
# Script to ...
################################################################################

# Check arguments
if ( $#argv != 1 ) then
    echo "Usage: $0 option1?"
    echo "Exiting."
    exit 1
endif

set OPTION1=$1



MATLAB
%% PROJECT TITLE
% 
% Stephen W. Thomas (sthomas@cs.queensu.ca)
% School of Computing, Queen's University, Canada
% Fall 2009
%
%
% Function to ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function R = features( inFileName ) 
   
%% Initialize stuff

    % GLOBALS
    global result;
   
    % CONSTANTS
    MAX         = 255;

    % Check arguments
    if (nargin < 1)
        fprintf('Usage: features imagename\n');
        fprintf('Exiting.\n');
        return;
    end