#! /bin/tcsh -f
# Purpose:
#    Runs a specified script, which may accept arguments, after setting up
#    for AIM processing running under the aiimsds account (released code only)
#
# Note: 
#    This script is modified from a similar script used to setup SORCE 
#    processing.
#
# Parameters:
#   $1 - The name of the script to run
#   $2- - Parameters intended as arguments to the script
#
# Date
#   March 21, 2007
#

set script = $argv[1]

# This gets the command line arguments, individually quoted
set cmdargs = ""
set i=2
set noglob  # don't want to do filename expansion at this point
while ($i <= $#argv)
    set arg = "$argv[$i]"
    if ( `echo $arg | grep "[\']"` != "" ) then
       # contains single quote(s)
       set quotsingle = '\"'"'"'\"'  # a quoted single quote: "'"
       # "escape" all single quotes
       set arg = `echo $arg | sed "s/\'/'$quotsingle'/g"`
    endif
    set cmdargs = "$cmdargs '$arg'"
    @ i++
end
unset noglob

echo "$script $cmdargs"

# Call the script on the command line arguments
eval "$script $cmdargs"
exit 0

# Done
