1

I need to run the program NACCESS on my MacOS X High Sierra.

The most prominent error is if: Expression Syntax.

This error is probably because the NACCESS executable is a CSH script with #!/bin/csh on its first line.

I changed the first line to #!/bin/bash and began getting errors such as ./naccess: line 14: syntax error near unexpected token `1' ./naccess: line 14: ` exit(1)'

Again, I think this is happening because the executable needs to be executed in a CSH shell, not bash. exit(1) is formatted for the CSH shell, whereas bash would want exit 1, according to this resource.

I tried typing csh into Terminal to switch shells, but an echo $SHELL command just tells me I'm still in bash.

I looked at my shell choices with grep '^#!' /usr/bin/* and cannot find any CSH shells. I attempted to download tcsh using homebrew. But I really have no idea what I'm doing at this point.

I know CSH shells aren't encouraged, but how do I get a CSH shell up and running on my Mac, or how do I otherwise get NACCESS to run?

[EDIT] Here are the first few lines of the NACCESS code:

(Note that I am running it with the .pdb file argument and also that I have set path_to_naccess_repository appropriately. I do get the usage naccess pdb_file [-p probe_size] [-r vdw_file] [-s stdfile] [-z zslice] -[hwyfaclqb] readout if I run only ./naccess)

#!/bin/csh
set EXE_PATH = /path/to/repo
#naccess_start

set nargs = $#argv
if ( $nargs < 1 ) then
   echo "usage naccess pdb_file [-p probe_size] [-r vdw_file] [-s stdfile] [-z zslice] -[hwyfaclqb]"
   exit(1)
endif

set PDBFILE = 0
set VDWFILE = 0
set STDFILE = 0
set probe = 1.40
set zslice = 0.05
set hets = 0
set wats = 0
set hyds = 0
set full = 0
set asao = 0
set cont = 0
set oldr = 0
set nbac = 0

while ( $#argv )
  switch ($argv[1])
     case -[qQ]:
    echo "Naccess2.1 S.J.Hubbard June 1996"
    echo "Usage: naccess pdb_file [-p probe_size] [-r vdw_file] [-s stdfile] [-z zslice] -[hwyfaclq]"
    echo " "
    echo "Options:"
    echo " -p = probe size (next arg probe size)"
    echo " -z = accuracy (next arg is accuracy)"
    echo " -r = vdw radii file (next arg is filename)"
    echo " -s = standard accessibilities file (next arg is filename)"
    echo " -h = hetatoms ?"
    echo " -w = waters ?"
    echo " -y = hydrogens ?"
    echo " -f = full asa output format ?"
    echo " -a = produce asa file only, no rsa file ?"
    echo " -c = output atomic contact areas in asa file instead of accessible areas"
    echo " -l = old RSA output format (long)"
    echo " -b = consider alpha carbons as backbone not sidechain"
    echo " -q = print the usage line and options list"
    echo " "
        exit
        breaksw
     case -[pP]:
    shift
    set probe = $argv[1]
    breaksw
     case -[zZ]:
        shift
        set zslice = $argv[1]
    breaksw
     case -[hH]:
        set hets = 1
    breaksw
     case -[wW]:
        set wats = 1
        breaksw
     case -[yY]:
        set hyds = 1
        breaksw
     case -[rR]:
        shift
        set VDWFILE = $argv[1]
        breaksw
     case -[sS]:
        shift
        set STDFILE = $argv[1]
        breaksw
     case -[fF]:
        set full = 1
        breaksw
     case -[aA]:
        set asao = 1
        breaksw
     case -[cC]:
        set cont = 1
        breaksw
     case -[lL]:
        set oldr = 1
        breaksw
     case -[bB]:
        set nbac = 1
        breaksw
     default:
        if ( -e $argv[1] && $PDBFILE == 0 ) then
       set PDBFILE = $argv[1]
        endif
    breaksw
  endsw
  shift
end
#
if ( $PDBFILE == 0 ) then
  echo "usage: you must supply a pdb format file"
  exit(1)
endif

[EDIT] I did NOT set the path appropriately >.< So this question is mainly about how to get a csh script running in bash. There are no problems with this csh script.

11
  • 1
    By C and C script you mean CSH and CSH script? those are quite different. The C tag is reserved for the C programming language, and CSH for C-Shell. Commented Sep 27, 2018 at 20:05
  • I have never used C or CSH before. I'm assuming it's CSH script, because of the exit(1) throwing an error. If I change it to exit 1, it moves on to the next syntax error. Commented Sep 27, 2018 at 20:06
  • Did you successfully install tcsh? Does the script work if you run tcsh ./naccess? Commented Sep 27, 2018 at 20:07
  • 1
    @briennakh This really sounds like a bug in the script, and not related to your setup. Your can try to run the program with all required parameters and hope this avoids triggering the bug, try to fix the script, or examine the script to see what it was supposed to do and then do those steps manually Commented Sep 27, 2018 at 20:16
  • 1
    /bin/csh and /bin/tcsh both ship with macOS. Commented Sep 27, 2018 at 20:18

2 Answers 2

2

The SHELL variable simply lists your first login shell, it will not change if you run another shell. echo $0 will show you you are running csh. Your options are either to stay in bash and change the shebang to tcsh:

#!/usr/bin/tcsh -f

or remove the shebang completely and run

csh ./naccess

If you are going for the first option, and not sure where csh is, just hit

which csh

to find the path. As the @Chepner adds, since the file comes with a csh shebang, don't touch it and just run it as above.

Sign up to request clarification or add additional context in comments.

6 Comments

The latter is better advice, since the original already had a csh shebang. (It may still require csh to be installed, but you can use your current shell's path lookup to avoid hard-coding the location of csh.)
I'm still getting if: Expression Syntax.?
@briennakh doing what? If you run csh ./nacess with a csh shebang (originally as you downloaded it) are you still getting the error?
Yes. I get if: Expression Syntax. if I keep the original csh shebang and run it with csh ./naccess. If I do which csh it shows that my csh is in /bin/csh.
@briennakh see my comment to your question. The only thing that can be done now is to actually have a look at the script.
|
1

If the first line of a script starts with #!, called a "shebang", that specifies how the script is executed if you invoke it as a command. It gives the full path of the interpreter to invoke and, optionally, an argument to pass to the interpreter, along with the script name.

If you have a script called foo whose first line is

#!/bin/csh

then typing ./foo is equivalent to /bin/csh foo. (The file foo has to be executable; use chmod +x if it isn't already.)

This is completely independent of (a) your login shell, (b), the shell you're currently running, and (c) the shell specified by the $SHELL environment variable.

You can invoke a script by explicitly typing the name of the shell used to run it, but the whole point of the #! is that you don't have to do that.

It's possible that /bin/csh doesn't exist on your system, or that it's something other than the C-shell.

tcsh is an updated version of csh. You should be able to use it to execute any csh script.

Find out where csh or tcsh is installed on your system and update the path in the #! line to refer to it. You might need to install either csh or tcsh yourself -- but you said you typed csh and it worked, so that shouldn't be necessary.

From a bash shell, the command type csh will tell you where csh is installed.

Incidentally, the #! line for a csh or tcsh script should include a -f option:

#!/bin/csh -f

This tells the shell not to source the user's startup script ($HOME/.cshrc) when running the script. It saves time and ensures that the script is portable, not dependent on one user's environment. (This does not apply to sh or bash scripts; sh and bash have a -f option, but it has a completely different meaning.)

I tried typing csh into Terminal to switch shells, but an echo $SHELL command just tells me I'm still in bash.

Invoking a shell doesn't change the value of your $SHELL environment variable. It's normally set to the path to your default login shell (but it can be changed).

You can tell if you're running tcsh by typing echo $tcsh or echo $version. (csh doesn't have these variables). You can tell if you're running bash by typing echo $BASH_VERSION.

1 Comment

Thank you so much for the details! Working with csh and the shell are new to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.