Find the answer to your Linux question:
Results 1 to 7 of 7
Hello forum members, I am trying to adapt a script originally written by programmers for csh to run in bash. The script calls a number of functions to calculate protein ...
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    6

    Unhappy csh to bash script conversion gives unexpected eof error

    Hello forum members, I am trying to adapt a script originally written by programmers for csh to run in bash. The script calls a number of functions to calculate protein conformational energy.
    I have changed a number of non-bash commands, such as setenv to export, and after
    many hours apt-getting new code, got to the stage where I could do a makefile and then source the .bashrc file (even though this has to be manually at the start of each session).

    However, there is a dreaded 'unexpected end of file' error flagged up when I do the
    following.........(my comments are marked with ##).

    ##source the .bashrc file##

    research1(at)heksaeder:~$ source /home/research1/.bashrc.eceppak

    ##OK so far, but then run the script recepp.s with appropriate arguments##

    research1(at)heksaeder:~$ recepp.s ENERGY H_alpha OUT x x 1

    ##The recepp-LNX.s file is pointed to by the generic recepp.s script, however I get the
    following error##

    /home/research1/eceppak/bin/recepp-LNX.s: line 238: syntax error: unexpected end of file

    ##I know that this refers probably to an incomplete if else endif sequence, but I cannot see
    where the problem might be...is if else endif the correct syntax for bash?##

    ##I also know that this is a common error that has been mentioned in the forum before, but
    I haven't found anything that would point me in the right direction I'm afraid##

    ##and the normal shell commands that are available before this script is run, such as ls and cd
    and the editor (nano) are no longer available, I have to re-open a new terminal window##

    research1(at)heksaeder:~$ nano /home/research1/eceppak/bin/recepp-LNX.s
    bash: nano: command not found

    ##The script recepp-LNX.s is listed below, sorry I could of course try reducing it whilst retaining
    the error, but I'm not a bash scripter, rather someone wanting to use a script that needs to work in a bash
    environment.##

    ##The recepp-LNX.s script lists as follows, and apologies for its length##


    #!/bin/bash -f
    # procedure to run new CSearch
    if ( $#argv == 0 ) then
    echo "You must specified the type of Run: recepp.s RUN_TYPE (+ ARGUMENTS)"
    echo "Where RUN_TYPE is one of the followings: "
    echo " ENERGY"
    echo " CHECKGRAD"
    echo " MINIMIZE"
    echo " EDMC"
    echo " RMS_FIT"
    echo " BOUNDS"
    echo " VTF"
    exit 1
    endif
    export RUNTYP=$1
    export RUN="TYPE0"
    if ( $1 == "ENERGY" ) then
    export RUN="TYPE1"
    endif
    if ( $1 == "CHECKGRAD" ) then
    export RUN="TYPE1"
    endif
    if ( $1 == "MINIMIZE" ) then
    export RUN="TYPE1"
    endif
    if ( $1 == "EDMC" ) then
    export RUN="TYPE1"
    endif
    if ( $1 == "RMS_FIT" ) then
    export RUN="TYPE2"
    endif
    if ( $1 == "BOUNDS" ) then
    export RUN="TYPE2"
    endif
    if ( $1 == "VTF" ) then
    export RUN="TYPE1"
    endif
    if ( $RUN == "TYPE0" ) then
    echo "Unrecognized option " $1
    echo "You must specified: recepp.s RUN_TYPE (+ ARGUMENTS)"
    echo "Where RUN_TYPE is one of the followings: "
    echo " ENERGY"
    echo " CHECKGRAD"
    echo " MINIMIZE"
    echo " EDMC"
    echo " RMS_FIT"
    echo " BOUNDS"
    echo " VTF"
    exit 1
    endif
    if ( $RUN == "TYPE1" ) then
    if ( $#argv < 5 ) then
    echo "Missing argument(s)! "
    echo "You must enter: recepp.s " $1 " ARG2 ARG3 ARG4 ARG5 "
    echo "ARG2 is the FILENAME of INPUT (*.inp) file (Input for the run)."
    echo "ARG3 is the FILETYPE of OUTPUT files."
    echo "ARG4 is the FILENAME of the ECEPP (outo.*) input file (if any) "
    echo " or a Dummy Argument "
    echo "ARG5 is the FILETYPE of Constraints (bounds.*) files or a "
    echo " Dummy argument if no constraints are used."
    exit 1
    endif
    export BNDF=$5
    export ANAF=$4
    endif
    if ( $RUN == "TYPE2" ) then
    if ( $1 == "RMS_FIT" ) then
    if ( $#argv < 5 ) then
    echo "Missing argument(s)! "
    echo "You must enter: recepp.s " $1 " ARG2 ARG3 ARG4 ARG5 "
    echo "ARG2 is the FILENAME of INPUT (*.inp) file (Input for the run)."
    echo "ARG3 is the FILETYPE of OUTPUT files."
    echo "ARG4 is the FILENAME of the PDB or ECEPP (outo.*) input file."
    echo "ARG5 is the FILENAME of the Reference (xray.*) file."
    exit 1
    endif
    export ANAF=$4
    export REFF=$5
    endif
    if ( $1 == "BOUNDS" ) then
    if ( $#argv < 4 ) then
    echo "Missing argument(s)! "
    echo "You must enter: recepp.s " $1 " ARG2 ARG3 ARG4 "
    echo "ARG2 is the FILENAME of INPUT (*.inp) file (Input for the run)."
    echo "ARG3 is the FILETYPE of OUTPUT files."
    echo "ARG4 is the FILENAME of the PDB input file."
    exit 1
    endif
    export ANAF=$4
    endif
    endif

    export INPF=$2
    export OUTF=$3

    echo $1 " CALCULATION"

    # IF names of files are too large (more than 64 characters) program won't run. In this case,
    # it is better to create a symbolic link to the appropriate directory.
    ln -s ${ECEPP_ROOT} ECEPP_ROOTA

    # ******** GENERAL INPUT FILES *************

    # Input for distance constraints
    # ln -s bounds.$BNDF fort.7

    # The following is the standard input file.
    # ln -s $INPF.inp fort.8

    # Input file containing the series of conformations whose energies
    # must be evaluated or minimized ("MULT_CONF" control card).
    # ln -s outo.$ANAF fort.11

    # INPUTS FOR SURFACE AREA AND HYDRATION MODELS
    # Parameters giving the free energy density for various solute atoms radii.
    export SOLVDBS=ECEPP_ROOTA/Data/Hydration/
    export SOLVFILE=$SOLVDBS/srfopt.set
    # Joe's solvation model.
    # export SOLVFILE=ECEPP_ROOTA/Data/Hydration/volume.set
    export FXVOLFILE=ECEPP_ROOTA/Data/Hydration/fix_vol_tst.parm

    # rsdata is a version of the STANDARD AMINO ACID DICTIONARY
    # containing the ECEPP/3 residues and other non-standard ones.
    # NP in PRO's was replaced by N to increase compatibility
    # with PDB files.
    #
    # Atom type of protons in COOH groups ( ASP, GLU, meASP, meGLU
    # and Carboxyl end terminal) changed to type 1, as in ECEPP/3
    # (no H-bonding allowed).
    #
    # passing database directory to program
    export RSDBS=ECEPP_ROOTA/Data/Residue/

    export RSDATA=ECEPP_ROOTA/Data/Residue/rsdata

    # File defining proton labels for each residue (for NMR purposes).
    # ln -s $ECEPP_ROOT/Data/Residue/nmr_protonsT.data fort.33
    export HLABELFILE=ECEPP_ROOTA/Data/Residue/nmr_protons.data

    export DIHDEFILE=ECEPP_ROOTA/Data/Residue/dihedral_def

    # Parameters for the unified residue approximation, the radius of
    # each residue in the sequence. NOT IMPLEMENTED ON THIS VERSION DR 2-94
    # RESRAD = UNIT 37
    # ln -s resrad.data fort.37

    # Atomic charges for IBEM
    export IBEMCHG=ECEPP_ROOTA/Data/IBEM/resibem

    # Atomic radii for IBEM

    # ln -s ECEPP_ROOTA/data/IBEM/atrad.siz fort.29
    # export ATMRAD=ECEPP_ROOTA/Data/IBEM/atrad.siz

    # Run parameters for IBEM

    # ln -s ECEPP_ROOTA/Data/IBEM/input.ibe fort.1
    # export IBEINFILE=ECEPP_ROOTA/Data/IBEM/input.ibe

    # **********************************************

    # / ********* GENERAL OUTPUT FILES *********/

    # ln -s outo.$OUTF fort.4
    # ln -s standout.$OUTF fort.6
    # ln -s sumsl.$OUTF fort.9

    # Output file for BOUNDS runs.
    # ln -s bounds.$OUTF fort.12
    # ln -s main_out.$OUTF fort.20

    # IBEM List file

    # ln -s ibe.$OUTF fort.2
    # export IBEOUTFILE=$OUTF

    # Be aware that UNIT 30 is used to print cartesian coordinates in OUTNW
    # routine. It is not assigned by this script.

    # The following definition can be used to print the APS matrix (Ken Gibson's
    # compact form of the VDW and RO parameters), from BD11 subroutine.
    # Write statement is currently commented out.
    # ln -s APS.$2 FILE.FT91F001

    # print identification of files
    echo "input file $INPF.inp "
    echo "Identification Argument of output files " $OUTF


    # Area optimization, the target areas for each residue in the sequence.
    # TGTARS = UNIT 38
    export TGTARS=TARGET.tgtars

    #
    #/* ******* INPUT-OUTPUT FILES ******** */
    # ln -s edmc.rstart fort.17
    export RESTFILE=edmc.rstart

    # ln -s edmc.rndom fort.18
    setenv RANDFILE edmc.rndom


    # if ( $RUN == "TYPE2" ) then

    # **********************************************
    # /* INPUT FILES RMS */
    #
    # Input conformation used to generate a REFERENCE file.
    # ln -s $REFF.pdb fort.27

    # This file contains the REFERENCE conformation.
    # ln -s xray.$REFF fort.57

    # When comparing two pdb files the input file is assigned to unit 44.
    # The program will compare the conformation on this file with (a) the one
    # in UNIT 57 (xray.*); or (b) that in UNIT 27.
    # ln -s $ANAF.pdb fort.44

    # /* OUTPUT FILES RMS */

    # ln -s sidev.$OUTF fort.22
    # ln -s hedev.$OUTF fort.26
    # ln -s badev.$OUTF fort.31
    # ln -s rgyr.$OUTF fort.34
    # ln -s xray.$OUTF fort.39
    # ln -s chefol.$OUTF fort.46
    # ln -s comso.$OUTF fort.47
    # ln -s cmsdk.$OUTF fort.48
    # ln -s kmsba.$OUTF fort.49
    # **********************************************
    # endif

    # The name of the ECEPPAK executable goes here:
    nice ECEPP_ROOTA/bin/eceppak-${ECEPP_ARCH}

    endif
    # it is possible to create a symbolic link to the appropriate directory.
    /bin/rm ECEPP_ROOTA

    ##thanks in advance if anyone has the patience to look through this script and to suggest
    what my be a problem and worth testing##


    Steve

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    109
    I ran a 'grep -w' on your code to count and identify the number of 'if' s and 'endif' s. If I ran on the precise code you setout properly I count 17 'endif' s and only 16 'if' s. I counted only non-commented pairs. Not sure this is the only problem with the code but may be one of them. Cheers..
    Robert

  3. #3
    Just Joined!
    Join Date
    Aug 2009
    Posts
    6
    Robert,

    thanks for the quick reply...I looked through the script and removed the last endif statement but to no avail.
    I know that sometimes there are hidden characters or spaces where there shouldn't be in scripts like this, but essentially this script has worked for other researchers using presumably the csh...but your reply was much appreciated thanks and welcome to the forum!!

    Steve

  4. #4
    Linux Newbie
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    109
    Hi labmonkey
    I see that you do have an instance of setenv, line 200 in your script, not changed to export. This will usually kil a script at runtime. Cheers...
    Robert

  5. #5
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    First I suggest you change the shebang line to:

    Code:
    #!/bin/bash -fvx
    This will list the commands as they are being executed. This will help in debugging the script.

    Next the syntax for the 'if' command is as follows as according to the bash manpage:

    if list; then list; [ elif list; then list; ] ... [ else list; ] fi
    Therefore you have to change all the 'endif' to 'fi'. This will at least get you a little farther.

    I don't know csh so I can't help more than this. You'll have to look at each error one at a time and figure out what the csh command is equivalent in bash.

  6. #6
    Just Joined!
    Join Date
    Aug 2009
    Posts
    6
    Hi,

    argh always one that slips through....but changing the setenv to export didn't cure the problem...something else lurks within....thanks for your continued help though

    Steve

  7. #7
    Just Joined!
    Join Date
    Aug 2009
    Posts
    6
    OK. I wasn't sure about the if else endif syntax so I will change these and see what that brings...also thanks for the suggestion to make the command execution verbose. Thanks for your help.

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...