Shell script suddenly not working

I've been having a shell script working file with no changes in the last month( which is actually stored in git repo).

But today when i run it is giving these errors:

% sh
: not found1:
: not found2: 3: set: Illegal option -

When I removed the 3rd line again a new bunch of errors. Yesterday some sever problem was there as Mysql crashed twice. Mine is Ubuntu 12.04.4 LTS

Here is the script code:

set -x


rm -f $tmp1 $tmp2 /tmp/vars.log /tmp/funcs.log


files="$bankstr myscript.js options.js user-selections.js background.js common.js client_server_common.js  injected/remove-alert.js"

for i in  $files
        cat $i| /home/ragu/railways/jsparser/collectSymbols> $tmp2
        cat $i| php /home/ragu/railways/jsparser/find_patterns.php >> /tmp/funcs.log

if [ ! -f $i ]
echo "$i not found! ..."
exit 1

for i in $files
        cat $i| php /home/raggupta/railways/jsparser/replace.php> $tmp1
        yui-compressor $tmp1 > $i
rm $tmp1

1 Reply

This is mostly a guess, but your script may have carriage returns (CR) that are screwing things up. Linux and Unix use a linefeed (LF) to mark the end of a line, while Windows uses a CR and an LF. This causes problems when editing the same file on both Windows and Linux.

You can check this by running cat -v - if you see "^M" at the end of each line, then that's the problem. It can be fixed with recode IBM-PC..latin1 or sed -i 's/\r$//'


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct