Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

 # 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  

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.

share|improve this question
I believe the first line should be #! /bin/bash – SimplySimon Jul 28 '13 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 '13 at 16:08
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 '13 at 16:42

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


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

share|improve this answer
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 '13 at 19:12

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 purge csh

In rest, the script looks ok.

share|improve this answer
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 '13 at 19:07
@Laskaris Then see this answer. – Radu Rădeanu Jul 28 '13 at 19:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.