0

I am trying to run the following script which will start a simulation run with a climate simulation program:

#!/bin/csh  
 # run-script generated by Most Tue Jul 23 13:10:46 2013
set EXP=MOST # Name your experiment here  
unset noclobber
if ($1 != "") cd $1  
 # rm -f plasim_restart
cp MOST_REST.010 plasim_restart  
rm -f Abort_Message  
set YEAR = 10  
set YEARS = 50  
while ($YEAR < $YEARS)  
set YEAR = `expr $YEAR + 1`  
set DATANAME=`printf '%s.%03d' $EXP $YEAR`  
set DIAGNAME=`printf '%s_DIAG.%03d' $EXP $YEAR`  
set RESTNAME=`printf '%s_REST.%03d' $EXP $YEAR`  
./most_plasim_t42_l10_p1.x >${DIAGNAME}  
if (-e Abort_Message) exit 1  
if (-e puma_output) mv puma_output $DATANAME  
if (-e puma_diag ) mv puma_diag $DIAGNAME  
cp plasim_status plasim_restart  
mv plasim_status $RESTNAME  
end 

When I try to run it, I get the following error message:

./most_plasim_run: line 1: ?#!/bin/csh: No such file or directory  
./most_plasim_run: line 5: syntax error near unexpected token `cd'  
./most_plasim_run: line 5: `if ($1 != "") cd $1'

I am mystified by this error message because I do in fact have bin/csh. I don't know where the problem is.

3
  • I believe the first line should be #! /bin/bash
    – Simon
    Jul 28, 2013 at 16:01
  • Added code tags... they should be added whenever you paste large blocks of code, so it's easier for others to read through it.
    – Wolfer
    Jul 28, 2013 at 16:08
  • 2
    I wonder why the first error reads line 1: ?#!/bin/csh – did you perhaps save this file with a byte-orden mark (BOM)?
    – MPi
    Jul 28, 2013 at 16:42

2 Answers 2

2

You most likely have one or more non-printing characters at the start of the script, which are invisible when you look at the script in an editor (or via 'cat') but are preventing the correct csh interpreter from being invoked. The remaining errors are probably just because the system is falling back to the default (bash) shell in which syntax like

if ($1 != "") cd $1

is incorrect, and will disappear once you fix the shebang line so that the intended shell is invoked.

I'm not sure the best way to remove non-printing characters - you could try something like

sed -i '1 s/^[^#]*//' most_plasim_run

which will delete anything up to the first # character in line 1 of the script - or you could open a new empty file and insert a 'clean' shebang line

#!/bin/csh

and then copy and paste the rest of the script in and re-save it.

1
  • It seems like I really had some non-printing characters at the start of the script (no idea how that happened, but I guess it did). Your recommendation to remove the non-printing characters with the sed command seems to have solved the problem. Script is running fine now. Thank you very much!
    – Laskaris
    Jul 28, 2013 at 19:12
1

You get those errors because you don't have csh shell interpreter installed. csh is a shell with C-like syntax. To install it, run next command in terminal:

sudo apt-get install csh

In rest, the script looks ok.

2
  • I thought I had csh installed. I ran your command, but that did not fix the problem. I still get the same error when I try to run my script.
    – Laskaris
    Jul 28, 2013 at 19:07
  • @Laskaris Then see this answer. Jul 28, 2013 at 19:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .